无法在 magento 2 rest 中使用贝宝下订单 [英] Not able to place the order using paypal in magento 2 rest

查看:21
本文介绍了无法在 magento 2 rest 中使用贝宝下订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

1.创建购物车

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

这个 api 将返回一个唯一的购物车 id

2.将产品加入购物车

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

身体 ->

<代码>{购物车项目":{quote_id":cartId,"sku": skuName,数量":1}}

<代码>3.估计运输方式

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

身体 ->

<代码>{地址": {"region": "特里凡得琅",region_id":12,"region_code": "CA","country_id": "IN",街道": [阿姆斯特之家",埃拉玛"],"电话": "5656565454","邮政编码": "670390","city": "卡扎库塔姆","firstname": "彼得","姓氏": "K","same_as_billing": 0,save_in_address_book":0}}

这将根据送货地址返回所有可能的送货方式.在我的情况下,结果是

<预><代码>[{"carrier_code": "免费送货","method_code": "免费送货","carrier_title": "免费送货","method_title": "免费",金额":0,基数":0,可用":真实,错误信息": "","price_excl_tax": 0,price_incl_tax":0}]

4)保存送货信息

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

正文数据 ->

<代码>{地址信息": {收件地址": {"region": "特里凡得琅",region_id":12,"region_code": "CA","country_id": "IN",街道": [阿姆斯特之家",埃拉玛"],"电话": "5656565454","邮政编码": "670390","city": "卡扎库塔姆","firstname": "彼得","姓氏": "K",},帐单地址": {"region": "特里凡得琅",region_id":12,"region_code": "CA","country_id": "IN",街道": [阿姆斯特之家",埃拉玛"],"电话": "5656565454","邮政编码": "670390","city": "卡扎库塔姆","firstname": "彼得","姓氏": "K",},"shipping_method_code": "免费送货","shipping_carrier_code": "免费送货"}}

这将返回所有可能的付款方式.在这里,我使用 paypal_express 付款.

<代码>5.使用paypal插件付款

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

这个api会返回如下数据,

<代码>{客户": {环境":沙箱","paypal_sdk_version": "2.14.4","平台": "安卓","product_name": "PayPal-Android-SDK"},回复": {"create_time": "2016-11-19T05:25:46Z","id": "PAY-5VS11410F5341972MLAX6ETA","意图": "销售",状态":已批准"},response_type":付款"}

5.保存付款并下单

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

数据 ->

<代码>{"cartId": 3,账单地址":{"region": "特里凡得琅",region_id":12,"region_code": "CA","country_id": "IN",街道": [阿姆斯特之家",埃拉玛"],"电话": "5656565454","邮政编码": "670390","city": "卡扎库塔姆","firstname": "彼得",姓氏":K"},付款方式": {方法":paypal_express"}}

但是这个api会返回

<代码>{"message": "PayPal 网关拒绝了请求.无效的令牌 (#10410: 无效的令牌)."}

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

解决方案

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

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

我正在写一篇关于这一步的完整文章.完成后我会通知你.

I am developing an e-commerce mobiloe application using magento 2 rest apis only.This is the flow for making the REST API calls for order placement.

1.Create a cart

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

This api will return a unique cart id

2.Add products to cart

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

body ->

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

3. Estimate Shipping Methods

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

body ->

{
    "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
    }

}

This will return all possible shipping methods based on shipping address.In my case the result is

[
  {
    "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)Save shipping information

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

body data ->

{
    "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"


    }
}

This will return all possible payment methods. Here i am using paypal_express for payment.

5. Payment using paypal plugin

Here i will pay the amount using paypal cordova plugin.Also configured the IPN [{{url}}/paypal/ipn/]in paypal account

This api will return the following data,

{
   "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.Save payment and place order

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

data ->

{
    "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"

    }
}

But this api will returning

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

Is there any api missing in the above flow for capturing payments.Please help me.

解决方案

Paypal Express payment method doesn't support online capturing. There is no way to get a full order creation flow like on Checkout via Magento API interface. It is impossible to change the order state and process payments. As a workaround try the following:

  1. Create a custom payment method
  2. Enable for REST API only(Not on website checkout page)
  3. While making payment using rest api use this method (after successful payment using you android/ios SDK)
  4. After placing the order make send transaction id(PAY-xxxxx) return by paypal sdk payment to save trasaction.(tell your server side tio implement this call).

I am writting a complete atrticle regarding this step by step. I will let you know when it is done.

这篇关于无法在 magento 2 rest 中使用贝宝下订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆