如何使用Demandware OCAPI在下达的订单中添加付款交易状态?

时间:2018-11-20 13:32:20

标签: api e-commerce payment-processing demandware

我正在为Demandware上的电子商务网站的移动应用程序开发API。我正在使用OCAPI 18.8下订单并将付款详细信息发送给Vantiv的第三方付款处理器。我从Vantiv获得了交易ID和响应代码,并希望更新订单以将这些付款交易详细信息存储到我的订单中。但是我在OCAPI中找不到任何资源,无法添加从Vantiv接收到的交易ID和响应代码。以下是我通过OCAPI放置的顺序:

{
"_v": "18.8",
"_type": "order",
"_resource_state": "xyz",
"adjusted_merchandize_total_tax": 0,
"adjusted_shipping_total_tax": 0,
"billing_address": {
    "_type": "order_address",
    "city": "Boston",
    "country_code": "US",
    "first_name": "John",
    "full_name": "John Martin",
    "id": "xyz",
    "last_name": "Martin"
},
"channel_type": "storefront",
"confirmation_status": "not_confirmed",
"created_by": "Customer",
"creation_date": "2018-11-20T10:37:58.055Z",
"currency": "USD",
"customer_info": {
    "_type": "customer_info",
    "customer_id": "xyz",
    "customer_name": "Ammar Shahbaz",
    "customer_no": "xyz"
},
"customer_name": "Ammar Shahbaz",
"export_status": "not_exported",
"last_modified": "2018-11-20T10:37:58.376Z",
"merchandize_total_tax": 0,
"notes": {
    "_type": "simple_link",
    "link": "link"
},
"order_no": "123",
"order_token": "xyz",
"order_total": 299.8,
"payment_instruments": [
    {
        "_type": "order_payment_instrument",
        "amount": 299.8,
        "payment_card": {
            "_type": "payment_card",
            "card_type": "Visa",
            "credit_card_expired": false,
            "expiration_month": 1,
            "expiration_year": 2021,
            "holder": "John Doe",
            "masked_number": "************4240",
            "number_last_digits": "4240"
        },
        "payment_instrument_id": "xyz",
        "payment_method_id": "CREDIT_CARD"
    }
],
"payment_status": "not_paid",
"product_items": [
    {
        "_type": "product_item",
        "adjusted_tax": 0,
        "base_price": 149.9,
        "bonus_product_line_item": false,
        "gift": false,
        "item_id": "xyz",
        "item_text": "Long Sleeve Sequin Shift Dress",
        "price": 299.8,
        "price_after_item_discount": 299.8,
        "price_after_order_discount": 299.8,
        "product_id": "xyz",
        "product_name": "Dress",
        "quantity": 2,
        "shipment_id": "xyz",
        "tax": 0,
        "tax_basis": 299.8,
        "tax_class_id": "xyz",
        "tax_rate": 0,
        "c_cost": 25.17,
        "c_finalSale": false,
        "c_outlet": false,
        "c_taxClassID": "xyz"
    }
],
"product_sub_total": 299.8,
"product_total": 299.8,
"shipments": [
    {
        "_type": "shipment",
        "adjusted_merchandize_total_tax": 0,
        "adjusted_shipping_total_tax": 0,
        "gift": false,
        "merchandize_total_tax": 0,
        "product_sub_total": 299.8,
        "product_total": 299.8,
        "shipment_id": "xyz",
        "shipment_total": 299.8,
        "shipping_address": {
            "_type": "order_address",
            "city": "Boston",
            "country_code": "US",
            "first_name": "John",
            "full_name": "John Martin",
            "id": "xyz",
            "last_name": "Martin"
        },
        "shipping_method": {
            "_type": "shipping_method",
            "description": "Order received within 5-8 business days",
            "id": "xyz",
            "name": "Standard",
            "price": 0,
            "shipping_promotions": [
                {
                    "_type": "shipping_promotion",
                    "callout_msg": "Free shipping on U.S. orders of $125+",
                    "link": "link",
                    "promotion_id": "xyz",
                    "promotion_name": "Free Shipping With $125 Purchase"
                }
            ],
            "c_BxFlatrateFlag": false,
            "c_IsBorderlinxMethod": false
        },
        "shipping_status": "not_shipped",
        "shipping_total": 0,
        "shipping_total_tax": 0,
        "tax_total": 0
    }
],
"shipping_items": [
    {
        "_type": "shipping_item",
        "adjusted_tax": 0,
        "base_price": 0,
        "item_id": "xyz",
        "item_text": "Shipping",
        "price": 0,
        "price_after_item_discount": 0,
        "shipment_id": "xyz",
        "tax": 0,
        "tax_basis": 0,
        "tax_class_id": "xyz",
        "tax_rate": 0
    }
],
"shipping_status": "not_shipped",
"shipping_total": 0,
"shipping_total_tax": 0,
"site_id": "site name",
"status": "created",
"taxation": "net",
"tax_total": 0

}

我已经尝试过此资源

Patch /orders/{order_no}/payment_instruments/{payment_instrument_id} 
{
 "amount" : 299.8,
 "payment_card" : {
                 "number":"424459xxxxxx4240",
                 "security_code":"121",
                 "holder":"John Martin",
                 "card_type":"Visa",
                 "expiration_month":1,
                 "expiration_year":2021
                },
"payment_method_id" : "CREDIT_CARD",
"c_PaymentProcessor": "VANTIV_CREDIT",
"c_paymentTransaction": {
  "custom": { 
    "litleAFTresponse": "Approved",
    "litleAFTTxnId": "8283868xxx8288282"
  }
}

}

更新我的订单,但没有成功。 如果您有任何建议,请告诉我。谢谢。

4 个答案:

答案 0 :(得分:0)

在商业云内部,以下方法调用设置了交易ID:paymentInstrument.paymentTransaction.setTransactionID(anTransactionId),因此您的假设是正确的。但是,该字段未在shop API中公开。从文档中可以清楚地看到,付款授权应由商业云触发。这是一个安全约束。可以自定义API来规避此限制。

答案 1 :(得分:0)

平台本身具有一些内部工作流程,您必须逐步遵循这些工作流程才能通过OCAPI Rest Api完成订单。您应该遵循分步工作流程,或者如果找不到,请让您的DW架构师为您提供指导。

答案 2 :(得分:0)

如果由于某种原因您在商业云外部进行了付款身份验证,则可以处理自定义请求文档属性中的内容。请注意,有一个选项可以通过skip_authorization参数跳过CC中的“授权”。例如:

POST /shop/v19_3/orders/00000027/payment_instruments?skip_authorization=true HTTP/1.1
Host: example.com
Authorization:Bearer eyJfdiI6IjXXXXXX.eyJfdiI6IjEiLCJleHAXXXXXXX.-d5wQW4c4O4wt-Zkl7_fiEiALW1XXXX 
Content-Type: application/json
{
  "amount": 49.99,
  "payment_method_id": "MY_PAYMENT_METHOD",
  "c_payment_token": "tokenvaluehere==",
  "c_payment_status": "payment_status"
}

然后在您的dw.ocapi.shop.order.payment_instrument.afterPOST中,您可以通过B2C API方法将属性添加到订单的PaymentInstrument,可通过回调的order参数访问这些属性。

您将需要签入beforePOST钩子,以确保c_payment_status参数是可接受的值,如果没有返回Status.ERROR类型的状态对象。然后,您实际上可以将属性保存在afterPOST钩子中,在该钩子中已经创建了需要的对象。

例如:

exports.paymentInstrumentAfterPOST = function(order, paymentInstrumentRequest) {
  const PaymentTransaction = require('dw/order/PaymentTransaction');
  const Status = require('dw/system/Status');
  const Transaction = require('dw/system/Transaction');
  let methodId = paymentInstrumentRequest.payment_method_id;
  let instruments = order.getPaymentInstruments(methodId);
  let instrument = instruments[0]; // FIXME you should actually iterate over this instead; just for demo
  let paymentTransaction =  instrument.getPaymentTransaction();

  Transaction.begin();
  paymentTransaction.setTransactionID(paymentInstrumentRequest.c_payment_token);
  paymentTransaction.setType(PaymentTransaction.TYPE_AUTH);

  Transaction.commit();

  return new Status(Status.OK);
}

有关自定义付款流程的更多信息,请参见Orders resource documentation

免责声明,这是用StackOverflow的答案表格自由编写的所有代码。我尚未验证此操作是否可以实际运行,但希望它能提供指导。

答案 3 :(得分:0)

截至今天,该平台提供了一种更好的方式来处理这一需求。在 DATA API Endpoints 下,您现在可以更新整体订单状态、付款、发货甚至送货地址。官方发行说明中的​​更多详细信息:

<块引用>

您现在可以使用数据 API 端点来更新服务器到服务器用例中的订单,例如订单管理系统或支付提供商发起更改时。

使用新的 PUT 命令更新不同类型的订单状态。

PUT /sites/{site_id}/orders/{order_no}/confirmation_status 
PUT /sites/{site_id}/orders/{order_no}/export_status 
PUT /sites/{site_id}/orders/{order_no}/external_status 
PUT /sites/{site_id}/orders/{order_no}/payment_status 
PUT /sites/{site_id}/orders/{order_no}/shipping_status 
PUT /sites/{site_id}/orders/{order_no}/status 
<块引用>

使用新的 PUT 命令更新订单的送货地址。

PUT /sites/{site_id}/orders/{order_no}/shipments/{shipment_id}/shipping_address
<块引用>

使用新的 PATCH 命令更新订单和付款属性。

PATCH /sites/{site_id}/orders/{order_no} 
PATCH /sites/{site_id}/orders/{order_no}/payment_instruments/{payment_instrument_id}
PATCH /sites/{site_id}/orders/{order_no}/payment_instruments/{payment_instrument_id}/transaction

来源:https://help.salesforce.com/articleView?id=sf.b2c_20_2_W6833203_ocapi_order_update_endpoints_as.htm&type=5