gpt4 book ai didi

php - 无法在 magento 2 rest 中使用 paypal 下订单

转载 作者:搜寻专家 更新时间:2023-10-31 21:23:36 24 4
gpt4 key购买 nike

我正在开发一个仅使用 ma​​gento 2 rest api 的电子商务 mobiloe 应用程序。这是调用 REST API 以下订单的流程。

1.创建购物车

API -->{{url}}/index.php/rest/V1/carts/mine

此 api 将返回一个唯一的购物车 ID

2.将产品添加到购物车

api --> {{url}}/index.php/rest/V1/carts/mine/items

正文 ->

{
"cart_item": {
"quote_id": cartId,
"sku": skuName,
"qty": 1
}
}

3.估计运输方式

url --> {{url}}/index.php/rest/V1/carts/mine/estimate-shipping-methods

正文 ->

{
"address": {
"region": "Trivandrum",
"region_id": 12,
"region_code": "CA",
"country_id": "IN",
"street": [
"Amstor house",
"Eramam"
],
"telephone": "5656565454",
"postcode": "670390",
"city": "Kazhakuttam",
"firstname": "Peter",
"lastname": "K",
"same_as_billing": 0,
"save_in_address_book": 0
}

}

这将根据送货地址返回所有可能的送货方式。在我的例子中,结果是

[
{
"carrier_code": "freeshipping",
"method_code": "freeshipping",
"carrier_title": "Free Shipping",
"method_title": "Free",
"amount": 0,
"base_amount": 0,
"available": true,
"error_message": "",
"price_excl_tax": 0,
"price_incl_tax": 0
}
]

4)保存发货信息

url --> {{url}}/index.php/rest/V1/carts/mine/shipping-information

body 数据->

{
"addressInformation": {
"shipping_address": {

"region": "Trivandrum",
"region_id": 12,
"region_code": "CA",
"country_id": "IN",
"street": [
"Amstor house",
"Eramam"
],
"telephone": "5656565454",
"postcode": "670390",
"city": "Kazhakuttam",
"firstname": "Peter",
"lastname": "K",

},
"billing_address": {
"region": "Trivandrum",
"region_id": 12,
"region_code": "CA",
"country_id": "IN",
"street": [
"Amstor house",
"Eramam"
],
"telephone": "5656565454",
"postcode": "670390",
"city": "Kazhakuttam",
"firstname": "Peter",
"lastname": "K",
},
"shipping_method_code": "freeshipping",
"shipping_carrier_code": "freeshipping"


}
}

这将返回所有可能的付款方式。我在这里使用 paypal_express 进行支付。

5.使用paypal插件支付

在这里,我将使用 paypal cordova plugin 支付金额.同时在paypal账户中配置IPN [{{url}}/paypal/ipn/]

此 api 将返回以下数据,

{
"client": {
"environment": "sandbox",
"paypal_sdk_version": "2.14.4",
"platform": "Android",
"product_name": "PayPal-Android-SDK"
},
"response": {
"create_time": "2016-11-19T05:25:46Z",
"id": "PAY-5VS11410F5341972MLAX6ETA",
"intent": "sale",
"state": "approved"
},
"response_type": "payment"
}

5.保存付款并下单

url --> {{url}}/index.php/rest/V1/carts/mine/payment-information

数据->

{
"cartId": 3,
"billingAddress‌​": {
"region": "Trivandrum",
"region_id": 12,
"region_code": "CA",
"country_id": "IN",
"street": [
"Amstor house",
"Eramam"
],
"telephone": "5656565454",
"postcode": "670390",
"city": "Kazhakuttam",
"firstname": "Peter",
"lastname": "K"
},
"paymentMethod": {
"method": "paypal_express"

}
}

但是这个api会返回

{
"message": "PayPal gateway has rejected request. Invalid token (#10410: Invalid token)."
}

上述流程中是否缺少用于捕获付款的 API。请帮助我。

最佳答案

Paypal Express 支付方式不支持在线捕获。无法通过 Magento API 接口(interface)获得像 Checkout 那样的完整订单创建流程。无法更改订单状态和处理付款。作为解决方法,请尝试以下操作:

  1. 创建自定义付款方式
  2. 仅为 REST API 启用(不在网站结帐页面上)
  3. 在使用 rest api 付款时使用此方法(在使用您的 android/ios SDK 成功付款后)
  4. 下订单后,通过 paypal sdk 支付返回发送交易 id(PAY-xxxxx) 以保存交易。(告诉您的服务器端实现此调用)。

我正在逐步写一篇关于这方面的完整文章。完成后我会通知您。

关于php - 无法在 magento 2 rest 中使用 paypal 下订单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41158020/

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