【问题标题】:How do I cancel/void an order using Paypal API V2?如何使用 Paypal API V2 取消/取消订单?
【发布时间】:2021-05-09 06:05:43
【问题描述】:

Paypal API V2 中的https://developer.paypal.com/docs/api/orders/v1/#orders_cancel 等价于什么?

授权订单后(使用带有“已创建”响应的 API v2 授权请求),我希望用户能够在单击按钮后取消订单。该按钮运行一个 cancel() 方法。

所以我的问题是,我应该在取消方法中提出什么请求来取消/取消使用 orderID 的现有订单?我知道我可以将订单保留在 V2 中,但我特别想取消/取消它。 (另外,我只能在给定的实现中使用 post、put 和 patch 请求)

如果您能为它提供 curl 命令或 nodeJS fetch 实现,将不胜感激。

提前谢谢你!

【问题讨论】:

    标签: paypal paypal-sandbox paypal-rest-sdk paypal-adaptive-payments


    【解决方案1】:

    如果 v2 订单是 intent:'authorize' 并且您“完成”它以取回授权对象,则可以使用 v2/payments API 取消授权。

    但是,如果订单只是“已创建”或“已批准”,则无法取消或取消订单。只需让您的系统忘记它。

    【讨论】:

    • 再次感谢您!请阅读我需要先发送保存请求,然后才能发送无效请求。尝试发送保存请求,得到“仅当 intent 为 AUTHORIZE 且 processing_instruction 为 ORDER_SAVED_EXPLICITLY 时,保存订单的选项才可用。”我尝试将其包含在保存请求的正文中,但没有奏效。我是否需要将其包含在我发送的授权请求正文中,还是需要在创建订单时发送?
    • 确保您在作废付款授权 ID,而不是订单 ID
    【解决方案2】:

    您不能使用 V2,但 V1 API 仍然可用,因此您可以使用该 API。

    Python 3.x 示例:

        import requests
        from requests.auth import HTTPBasicAuth
        
        def get_access_token(client_id, client_secret):
            res = requests.post(
                'https://api-m.sandbox.paypal.com/v1/oauth2/token',
                headers={
                    'Accept': 'application/json',
                    'Accept-Language': 'en_US',
                },
                auth=HTTPBasicAuth(client_id, client_secret),
                data={'grant_type': 'client_credentials'},
            ).json()
            return res['access_token']
        
        
        def cancel_order(access_token, order_id) -> bool:
            uri = f'https://api-m.sandbox.paypal.com/v1/checkout/orders/{order_id}'
            res = requests.delete(
                uri,
                headers={
                    'Content-Type': 'application/json',
                    'Authorization': f'Bearer {access_token}'
                }
            )
        
            if not res.ok:
                raise Exception(f"\n\nPayPal API Call failed for url {uri}: {res.reason} ({res.text}).\nFull Response:\n{res}\n\n")
        
            return
        
        
        acc_token = get_access_token('<<client_id>>', '<<client_secret>>')
        cancel_order(acc_token, '<<order_id>>')
    

    【讨论】:

      猜你喜欢
      • 2021-09-18
      • 2023-04-08
      • 2020-02-13
      • 2022-01-15
      • 2011-10-20
      • 2015-01-28
      • 2020-10-10
      • 2020-09-14
      • 2022-07-21
      相关资源
      最近更新 更多