我无法在Paypal付款集成中预先填写手机号码

时间:2019-03-18 09:57:34

标签: python paypal

payment = Payment({
    "intent": "sale",

    "application_context": {
        "locale": "en_IN",
        "user_action": "commit",
        "shipping_preference": "NO_SHIPPING",
        "landing_page": "billing"
    },

    # Set payment method
    "payer": {
        "payment_method": "paypal",
        "payer_info": {
            "email": email,
            "first_name": first_name,
            "last_name": last_name,
            "shipping_address": {
            "phone": phone,
            }
        }
    },

    # Set redirect URLs
    "redirect_urls": {
        "return_url": "example.com/confpayment/",
        "cancel_url": "examplecom/payment_fail/"
    },
    # Set transaction object
    "transactions": [{
        "amount": {
            "total": str(amount),
            # "total": "1",
            "currency": "INR"
        },
        "description": "payment description"
    }]
})

我收到传入的JSON请求未映射到API请求

  

错误:{'name': 'MALFORMED_REQUEST', 'message': 'Incoming JSON request does not map to API request', 'information_link': 'https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST', 'debug_id': '51397a89429bd'}

除手机号码外,其他所有东西都已预先填写。 请帮我解决这个问题。

我不确定API格式是否正确。

1 个答案:

答案 0 :(得分:0)

编辑预览代码错误:

此处payer属性的文档(链接已更正为V2):

https://developer.paypal.com/docs/api/orders/v2/?mark=payer#definition-payer

错误,请删除多余的逗号:"phone": "",

"payer_info": {
...
    "shipping_address": {
        "phone": ""
    }
 }

此代码错误:

phone移到shipping_address之外:

"payer_info": {
...
    "shipping_address": {
    ...
    },
    "phone": ""
 }

此处提供了完整示例:http://www.seneca-re.com/wp-content/plugins/estatik/vendor/paypal/rest-api-sdk-php/sample/payments/ListPayments.php