gpt4 book ai didi

PayPal REST API - 购买后状态不会改变

转载 作者:太空宇宙 更新时间:2023-11-03 15:41:12 25 4
gpt4 key购买 nike

所以我注意到在检查付款状态时

GET /v1/payments/payment/<Payment-Id>

PayPal 响应的“状态”不会从“已创建”改变,即使在 PayPal 用户购买了商品之后也是如此。直到我执行付款,状态才变为“已批准”

这使得很难区分客户实际批准的付款和仍在处理中的付款,因为它们都处于“已创建” 状态。 json 响应中的唯一区别是它似乎包含 shipping_address 一旦付款实际上已被批准。不过,我不确定这是表示差异的标准方法。

在使用上述 REST API 调用时判断客户是否实际批准 PayPal 交易的标准方法是什么?

注意:我已经设置并运行了 PHP 回调脚本。我正在开发一个故障安全系统,该系统会不断检查数据库条目以确保执行了批准的付款(以防出现某些系统故障)。

我想我可以使用我从 CLASSIC API 设置的 IPN 回调脚本,但似乎 REST APICLASSIC API 是不兼容,因为 IPN 回调将不包含事务 ID 或任何有用的必要信息。

似乎在使用 REST API 时,如果您错过了对网络服务器的重定向调用,那么该事务将永远丢失。

最佳答案

正确的是,您不会从查找 API 响应中的 state 字段中得知已批准的付款,相反,您会在JSON 正文,该信息将为您指示已批准的支付资源。

这是客户重定向(用户批准)之前/之后相同 PAY-ID 的 JSON 响应

  1. 查找付款/v1/payments/payment/PAY-9J02491382988403BK3BMC6I(用户批准前):

    {
    "id": "PAY-9J02491382988403BK3BMC6I",
    "intent": "sale",
    "state": "created",
    "cart": "07U14103P0008801U",
    "transactions": [ {
    "amount": {
    "total": "80.00",
    "currency": "USD"
    },
    "payee": {"email": "USM@email.com"},
    "invoice_number": "55a460ff696br",
    "item_list": {
    "items": [
    {
    "name": "Test Ticket 1",
    "sku": "55a460ff65f13",
    "price": "10.00",
    "currency": "USD",
    "quantity": 1
    },
    {
    "name": "Test Ticket 2",
    "sku": "55a460ff66c7a",
    "price": "20.00",
    "currency": "USD",
    "quantity": 2
    },
    {
    "name": "Test Ticket 3",
    "sku": "55a460ff66ce2",
    "price": "10.00",
    "currency": "USD",
    "quantity": 3
    }
    ],
    "shipping_address": {
    "recipient_name": "Test Name",
    "line1": "Main St 1",
    "city": "San Jose",
    "state": "CA",
    "postal_code": "95131",
    "country_code": "US"
    }
    },
    "related_resources": [],
    "notify_url": "https://bt-pduan-1.c9.io/ipn.php"
    }],
    "redirect_urls": {
    "return_url": "http://localhost:80/getpaypal?paymentId=PAY-9J02491382988403BK3BMC6I",
    "cancel_url": "http://localhost:80/cancel"
    },
    "create_time": "2016-02-16T06:28:08Z",
    "update_time": "2016-02-16T06:28:08Z",
    "links": [
    {
    "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-9J02491382988403BK3BMC6I",
    "rel": "self",
    "method": "GET"
    },
    {
    "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-9J02491382988403BK3BMC6I/execute",
    "rel": "execute",
    "method": "POST"
    },
    {
    "href": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-07U14103P0008801U",
    "rel": "approval_url",
    "method": "REDIRECT"
    }
    ]
    }
  2. 在用户批准后查找付款(我正在删除一些 JSON 内容,例如交易/url 数组以提高可读性):

    {
    "id": "PAY-9J02491382988403BK3BMC6I",
    "intent": "sale",
    "state": "created",
    "cart": "07U14103P0008801U",
    "payer": {
    "payment_method": "paypal",
    "status": "VERIFIED",
    "payer_info": {
    "email": "USP@email.com",
    "first_name": "Payer",
    "last_name": "US",
    "payer_id": "8FMFQ2KVYYHTY",
    "shipping_address": {
    "recipient_name": "Test Name",
    "line1": "Main St 1",
    "city": "San Jose",
    "state": "CA",
    "postal_code": "95131",
    "country_code": "US"
    },
    "phone": "408-743-9795",
    "country_code": "US",
    "billing_address": {
    "line1": "1 Main St",
    "line2": "",
    "city": "San Jose",
    "state": "CA",
    "postal_code": "95131",
    "country_code": "US"
    }
    }
    },
    "transactions": [],
    "redirect_urls": {},
    "create_time": "2016-02-16T06:28:08Z",
    "update_time": "2016-02-16T06:28:08Z",
    "links": []
    }

通过检查记录的 PAY-ID 在 API 响应中寻找 payer 对象,您将能够保存订单并继续执行调用,以防在客户返回重定向中遗漏它。

此外,在这种情况下,IPN 或 webhook 都无济于事,因为它们是由交易级事件触发的异步消息,这意味着在执行付款之前不会有通知。

关于PayPal REST API - 购买后状态不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35216925/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com