卖家PayPal账户未收到REST API付款



我正试图在django rest框架中实现服务器端的贝宝rest api,我不得不说贝宝的文档根本没有帮助,但到目前为止,我已经能够通过首先获得访问令牌:成功地从沙盒买家帐户付款

def generate_access_token():
url="https://api-m.sandbox.paypal.com/v1/oauth2/token"
headers={
'Content-Type': 'application/json'
}
auth=(settings.PAYPAL_CLIENT_ID,settings.PAYPAL_SECRET_KEY)
data={
"grant_type":"client_credentials"
}
response=requests.post(url,headers=headers,auth=auth,data=data)
token=response.json()['access_token']
return token

然后我创建一个订单,让买家支付:

def pay_for_order(token,price,order_id):
url="https://api-m.sandbox.paypal.com/v2/checkout/orders"
headers={
'Content-Type': 'application/json',
'Authorization':f'Bearer {token}'
}
data={
'intent':'CAPTURE',
'application_context':{
'return_url':f'http://127.0.0.1:8000/payment/confirm-payment/1/{token}/',
'cancel_url':f'http://127.0.0.1:8000/payment/confirm-payment/2/{token}/'
},
'purchase_units':[
{
"reference_id":f'{order_id}',
"amount":{
'currency_code':'USD',
'value':f'{price}'
}
}
]
}
response=requests.post(url,headers=headers,data=json.dumps(data))
print(response.json())
response_json=response.json()
return response_json

当付款成功时,订单捕获会在返回url中的端点中调用,如下所示:

def final_payment_verification(token,paypal_token):
url=f'https://api.sandbox.paypal.com/v2/checkout/orders/{paypal_token}/capture'
headers={
'Content-Type': 'application/json',
'Authorization':f'Bearer {token}'
}
response=requests.post(url,headers=headers)
print(response.json())
response_json=response.json()
return response_json

但现在的主要问题是,卖家没有被记入贷方。我的直觉是,用卖家的客户id和密钥生成访问令牌已经成为买家付款对象的标识,但不幸的是,只有买家被记入借方,我检查了贝宝文档上的整个订单api,但找不到需要买家或收件人信息的字段,所以贝宝可以向他们付款,所有在线解决方案都是客户端结账,贝宝文档根本没有帮助,甚至还有一些阅读更多的页面,导致完全不同的无关内容,每个在线资源大多使用v1版本,而不是最新的v2版本,我真的很想知道我做错了什么。

代码处于沙箱模式,因此您必须使用沙箱客户端ID和机密。您是否正在查找与您正在使用的REST应用程序客户端ID和机密相对应的卖家沙盒帐户(打开一个单独的选项卡,用它登录www.sandbox.paypal.com(?

如果您仍然有问题,请记录整个捕获API响应主体,并将其包含在您的问题中。

最新更新