【发布时间】:2017-04-30 16:38:30
【问题描述】:
我正在开发一个仅使用 magento 2 rest api 的电子商务 mobiloe 应用程序。这是为下订单进行 REST API 调用的流程。
1.Create a cart
api -->{{url}}/index.php/rest/V1/carts/mine
此 api 将返回一个唯一的购物车 id
2.Add products to cart
api --> {{url}}/index.php/rest/V1/carts/mine/items
身体->
{
"cart_item": {
"quote_id": cartId,
"sku": skuName,
"qty": 1
}
}
3. Estimate Shipping Methods
网址 --> {{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)Save shipping information
网址 --> {{url}}/index.php/rest/V1/carts/mine/shipping-information
身体数据 ->
{
"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. Payment using paypal plugin
这里我将使用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.Save payment and place order
网址 --> {{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 将在收到付款后发送 IPN。您应该使用它来下订单...否则您的客户可能会尝试通过对您的应用进行逆向工程来欺骗付款。
标签: php rest cordova paypal magento2