付款批准后如何获取return_url,以便可以在return_url中获取付款人ID?

时间:2019-05-12 06:56:12

标签: python-3.x paypal payment-gateway paypal-rest-sdk

要执行付款,我需要输入付款ID和付款人ID。现在,我有了从创建付款呼叫中获得的付款ID。但是付款人ID不包含在其中。我了解付款批准后可以从return_url获取付款人ID。那么,如何获得该return_url /付款人ID?

我尝试查看贝宝网站上的文档,其内容写为“#使用创建付款呼叫中的付款人ID执行付款(重定向后)。”这是我无法得到的部分。

class PayPal():
    paypalrestsdk.configure({
        "mode": "sandbox", # sandbox or live
        "client_id": "XXXXXXXXXXXXXXXXXXX",
        "client_secret": "XXXXXXXXXXXXXXXXXX" })

    def create_payment(self):
        payment = paypalrestsdk.Payment({
            "intent": "sale",
            "payer": {
                "payment_method": "paypal"},
            "redirect_urls": {
                "return_url": "http://www.example.com",
                "cancel_url": "http://www.example.com"},
            "transactions": [{
                "item_list": {
                    "items": [{
                        "name": "item",
                        "sku": "pcs",
                        "price": "5.00",
                        "currency": "USD",
                        "quantity": 1}]},
                "amount": {
                    "total": "5.00",
                    "currency": "USD"},
                "description": "This is the payment transaction description."}]})

        if payment.create():
            # Extract redirect url
            for link in payment.links:
                if link.method == "REDIRECT":
                    # Capture redirect url
                    redirect_url = (link.href)
                    webbrowser.open("%s"% (redirect_url))
                    print(link)
            print("Payment created successfully")
            print (payment)
        else:
            print("Error while creating payment:")

            print(payment.error)
    def execute_payment(self):
        payment = paypalrestsdk.Payment.find("%s" % payment.id)
        if payment.execute({"payer_id": "%s" % payment.payerid}):
            print("Payment[%s] execute successfully" % (payment.id))
        else:
            print(payment.error)

这是我在“创建付款”通话中得到的:

{'intent':'sale','payer':{'payment_method':'paypal'},'redirect_urls':{'return_url':'http://www.example.com','cancel_url':'{{ 3}}'},'交易':[{'amount':{'total':'5.00','currency':'USD'},'description':'这是付款交易的描述。','item_list ':{'items':[{'name':'item','sku':'pcs','price':'5.00','currency':'USD','quantity':1}]}}, 'related_resources':[]}],'id':'PAYID-xxxxxxxxxxxxxx','state':'created','create_time':'2019-05-12T06:37:19Z','links :: [{ href':'http://www.example.com','rel':'self','method':'GET'},{'href':'https://api.sandbox.paypal.com/v1/payments/payment/PAYID-xxxxxxxxxxxxxxxxx','rel':'approval_url',' method':'REDIRECT'},{'href':'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-xxxxxxxxxxxxx','rel':'execute','method':'POST'}]}}

0 个答案:

没有答案