疑問
どうして PayPal API はこれまでの PayPal APIを経由していない決済のトランザクションの履歴を取得できないのか?
検証
試しに PayPal API に2つアプリを登録して、決済とトランザクションの取得をそれぞれ実行しました。
Python
import paypalrestsdk
def pay_and_history():
# Make Payment
payment = paypalrestsdk.Payment({
"intent": "sale",
"payer": {
"payment_method": "paypal"},
"redirect_urls": {
"return_url": "http://localhost:3000/payment/execute",
"cancel_url": "http://localhost:3000/"},
"transactions": [{
"item_list": {
"items": [{
"name": "item",
"sku": "item",
"price": "10",
"currency": "JPY",
"quantity": 1}]},
"amount": {
"total": "10",
"currency": "JPY"},
"description": "This is the payment transaction description."}]})
if payment.create():
print("Payment created successfully")
else:
print(payment.error)
# Get Payment history.
payment_history = paypalrestsdk.Payment.all({"count": 10})
print("List Payment:{}".format(len(payment_history.payments)))
for payment in payment_history.payments:
print(" -> Payment[%s]" % (payment.id))
try:
# Retrieve the payment object by calling the
# `find` method
# on the Payment class by passing Payment ID
payment = paypalrestsdk.Payment.find(payment.id)
print("Got Payment Details for Payment[%s]" % (payment.id))
print(payment)
except ResourceNotFound as error:
# It will through ResourceNotFound exception if the payment not found
print("Payment Not Found")
print("App1")
# Authentification & Get Token
paypalrestsdk.configure({
"mode": "sandbox", # sandbox or live
'client_id': '***',
'client_secret': '***'})
pay_and_history()
print("App2")
# Authentification & Get Token
paypalrestsdk.configure({
"mode": "sandbox", # sandbox or live
'client_id': '***',
'client_secret': '***'})
pay_and_history()
結果
それぞれのアプリ内で実行した決済のみが取得されました。
Python
App1
Payment created successfully
List Payment:3
-> Payment[PAY-4B573760HU7618102LNME4WY]
Got Payment Details for Payment[PAY-4B573760HU7618102LNME4WY]
{'transactions': [{'description': 'This is the payment transaction description.', 'related_resources': [], 'item_list': {'items': [{'price': '10', 'currency': 'JPY', 'quantity': 1, 'sku': 'item', 'name': 'item'}]}, 'amount': {'currency': 'JPY', 'total': '10'}, 'payee': {'merchant_id': 'RZHSU678HRWR8', 'email': 'aaa+b@gmail.com'}}], 'redirect_urls': {'cancel_url': 'http://localhost:3000/', 'return_url': 'http://localhost:3000/payment/execute?paymentId=PAY-4B573760HU7618102LNME4WY'}, 'cart': '8059003180126730N', 'id': 'PAY-4B573760HU7618102LNME4WY', 'create_time': '2018-07-25T10:18:03Z', 'state': 'created', 'links': [{'href': 'https://api.sandbox.paypal.com/v1/payments/payment/PAY-4B573760HU7618102LNME4WY', 'rel': 'self', 'method': 'GET'}, {'href': 'https://api.sandbox.paypal.com/v1/payments/payment/PAY-4B573760HU7618102LNME4WY/execute', 'rel': 'execute', 'method': 'POST'}, {'href': 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-8059003180126730N', 'rel': 'approval_url', 'method': 'REDIRECT'}], 'update_time': '2018-07-25T10:18:05Z', 'intent': 'sale'}
-> Payment[PAY-3JP2876056031781GLNMEXDY]
Got Payment Details for Payment[PAY-3JP2876056031781GLNMEXDY]
{'transactions': [{'description': 'This is the payment transaction description.', 'related_resources': [], 'item_list': {'items': [{'price': '10', 'currency': 'JPY', 'quantity': 1, 'sku': 'item', 'name': 'item'}]}, 'amount': {'currency': 'JPY', 'total': '10'}, 'payee': {'merchant_id': 'RZHSU678HRWR8', 'email': 'aaa+b@gmail.com'}}], 'redirect_urls': {'cancel_url': 'http://localhost:3000/', 'return_url': 'http://localhost:3000/payment/execute?paymentId=PAY-3JP2876056031781GLNMEXDY'}, 'cart': '80M46118JJ147044H', 'id': 'PAY-3JP2876056031781GLNMEXDY', 'create_time': '2018-07-25T10:06:07Z', 'state': 'created', 'links': [{'href': 'https://api.sandbox.paypal.com/v1/payments/payment/PAY-3JP2876056031781GLNMEXDY', 'rel': 'self', 'method': 'GET'}, {'href': 'https://api.sandbox.paypal.com/v1/payments/payment/PAY-3JP2876056031781GLNMEXDY/execute', 'rel': 'execute', 'method': 'POST'}, {'href': 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-80M46118JJ147044H', 'rel': 'approval_url', 'method': 'REDIRECT'}], 'update_time': '2018-07-25T10:18:07Z', 'intent': 'sale'}
-> Payment[PAY-40Y25412PK326360YLNMEW2I]
Got Payment Details for Payment[PAY-40Y25412PK326360YLNMEW2I]
{'transactions': [{'description': 'This is the payment transaction description.', 'related_resources': [], 'item_list': {'items': [{'price': '10', 'currency': 'JPY', 'quantity': 1, 'sku': 'item', 'name': 'item'}]}, 'amount': {'currency': 'JPY', 'total': '10'}, 'payee': {'merchant_id': 'RZHSU678HRWR8', 'email': 'aaa+b@gmail.com'}}], 'redirect_urls': {'cancel_url': 'http://localhost:3000/', 'return_url': 'http://localhost:3000/payment/execute?paymentId=PAY-40Y25412PK326360YLNMEW2I'}, 'cart': '95A06012W9849542P', 'id': 'PAY-40Y25412PK326360YLNMEW2I', 'create_time': '2018-07-25T10:05:29Z', 'state': 'created', 'links': [{'href': 'https://api.sandbox.paypal.com/v1/payments/payment/PAY-40Y25412PK326360YLNMEW2I', 'rel': 'self', 'method': 'GET'}, {'href': 'https://api.sandbox.paypal.com/v1/payments/payment/PAY-40Y25412PK326360YLNMEW2I/execute', 'rel': 'execute', 'method': 'POST'}, {'href': 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-95A06012W9849542P', 'rel': 'approval_url', 'method': 'REDIRECT'}], 'update_time': '2018-07-25T10:18:08Z', 'intent': 'sale'}
App2
Payment created successfully
List Payment:2
-> Payment[PAY-8GK97765YB245513TLNME4YY]
Got Payment Details for Payment[PAY-8GK97765YB245513TLNME4YY]
{'transactions': [{'description': 'This is the payment transaction description.', 'related_resources': [], 'item_list': {'items': [{'price': '10', 'currency': 'JPY', 'quantity': 1, 'sku': 'item', 'name': 'item'}]}, 'amount': {'currency': 'JPY', 'total': '10'}, 'payee': {'merchant_id': 'SCRDP5GD3NSGQ', 'email': 'aaa+c@gmail.com'}}], 'redirect_urls': {'cancel_url': 'http://localhost:3000/', 'return_url': 'http://localhost:3000/payment/execute?paymentId=PAY-8GK97765YB245513TLNME4YY'}, 'cart': '3N278674BD1211813', 'id': 'PAY-8GK97765YB245513TLNME4YY', 'create_time': '2018-07-25T10:18:11Z', 'state': 'created', 'links': [{'href': 'https://api.sandbox.paypal.com/v1/payments/payment/PAY-8GK97765YB245513TLNME4YY', 'rel': 'self', 'method': 'GET'}, {'href': 'https://api.sandbox.paypal.com/v1/payments/payment/PAY-8GK97765YB245513TLNME4YY/execute', 'rel': 'execute', 'method': 'POST'}, {'href': 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-3N278674BD1211813', 'rel': 'approval_url', 'method': 'REDIRECT'}], 'update_time': '2018-07-25T10:18:14Z', 'intent': 'sale'}
-> Payment[PAY-55X1302146393943DLNMEXFQ]
Got Payment Details for Payment[PAY-55X1302146393943DLNMEXFQ]
{'transactions': [{'description': 'This is the payment transaction description.', 'related_resources': [], 'item_list': {'items': [{'price': '10', 'currency': 'JPY', 'quantity': 1, 'sku': 'item', 'name': 'item'}]}, 'amount': {'currency': 'JPY', 'total': '10'}, 'payee': {'merchant_id': 'SCRDP5GD3NSGQ', 'email': 'aaa+c@gmail.com'}}], 'redirect_urls': {'cancel_url': 'http://localhost:3000/', 'return_url': 'http://localhost:3000/payment/execute?paymentId=PAY-55X1302146393943DLNMEXFQ'}, 'cart': '3EP2220770918603W', 'id': 'PAY-55X1302146393943DLNMEXFQ', 'create_time': '2018-07-25T10:06:14Z', 'state': 'created', 'links': [{'href': 'https://api.sandbox.paypal.com/v1/payments/payment/PAY-55X1302146393943DLNMEXFQ', 'rel': 'self', 'method': 'GET'}, {'href': 'https://api.sandbox.paypal.com/v1/payments/payment/PAY-55X1302146393943DLNMEXFQ/execute', 'rel': 'execute', 'method': 'POST'}, {'href': 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-3EP2220770918603W', 'rel': 'approval_url', 'method': 'REDIRECT'}], 'update_time': '2018-07-25T10:18:16Z', 'intent': 'sale'}
つまり PayPal API はアプリ単位でトランザクションを管理しているため、 PayPal API 仕様以前の決済はアプリ外の情報なのでアクセスができない事がわかりました。
結論
PayPal API は複数のアプリを独立して管理するための機能であり、PayPalアカウント全体を管理・操作するためのものではないということです。
コメントを残す