Order Management {#salesforce-b2c-order-management}
===================================================

`Salesforce` B2C Commerce does not natively support order management functions. This cartridge has functions that can be used to process captures and authorization reversals.

> These functions must be customized before use in the ` Salesforce ` B2C Commerce user interface.
> *The ServiceFrameworkTest example controllers referenced below are for testing only. Access is granted only when **all** of the following are true:*

1. The Salesforce instance is **not** a production instance.
2. The **Enable Visa Acceptance Test Endpoints** preference (Custom Preferences \&gt; Visa Acceptance Cartridge configuration) is enabled. It is disabled by default.
3. The caller is an **authenticated, registered customer** who is a member of the `VisaAcceptanceTestAdmin` customer group

{#salesforce-b2c-order-management_ol_jkf_b2k_2kc}  
*The VisaAcceptanceTestAdmin customer group is not created by the metadata import --- you must create it in Business Manager under **Merchant Tools \&gt; Customers \&gt; Customer Groups** and assign it only to authorized merchant staff. Only members of this group can access the test endpoints; any request from a non-member (or an unauthenticated visitor) is redirected to the home page.*

Capture
-------

The capture function can be found in the script *scripts/http/capture.js*. A working example is available in the ServiceFrameworkTest-TestCaptureService controller.  
Reference the capture.js object and make this request:

```
var captureObj = require("~/cartridge/scripts/http/capture.js");
var serviceResponse = captureObj.httpCapturePayment(requestID, merchantRefCode, paymentTotal, currency);
```

The resulting serviceResponse object contains the full response object generated by the request. The contents of this object determine your logic in handling errors and successes. These are the Capture request parameters:  
**Capture Request Parameters:**

* requestID: The `Visa Acceptance for SMB` Request ID from the initial authorization.
* merchantRefCode: The `Salesforce` Order Number.
* purchaseTotal: The capture amount.
* currency: Currency Code.

**Function Signature:**

```
httpCapturePayment(requestID, merchantRefCode, purchaseTotal, currency)
```

Authorization Reversal
----------------------

The authorization reversal function can be found in the script called *scripts/http/authReversal.js*. A working example is in the ServiceFrameworkTest-TestAuthReversal controller.  
Reference the AuthReversal.js object and make this request:

```
var reversalObj = require("~/cartridge/scripts/http/authReversal.js");
var serviceResponse = reversalObj.httpAuthReversal(requestID, merchantRefCode, paymentTotal, currency);
```

The resulting serviceResponse object contains the full response object generated by the request. The contents of this object determine your logic in handling errors and successes. These are the Authorization reversal request parameters:  
**Authorization Reversal Request Parameters:**

* requestID: The `Visa Acceptance for SMB` Request ID from the initial authorization.
* merchantRefCode: The `Salesforce` Order Number.
* purchaseTotal: The reversal amount.
* currency: Currency Code.

Refund
------

The refund function can be found in the script called *scripts/http/refund.js*. A working example is in the ServiceFrameworkTest-RefundService controller.  
Reference the refund.js object and make this request:

```
var refundObj = require("~/cartridge/scripts/http/refund.js");
var serviceResponse = refundObj.httpRefundPayment(transactionId, merchantRefCode, paymentTotal, currency, refundEndpointType);
            
```

The resulting serviceResponse object contains the full response object generated by the request. The contents of this object determine your logic in handling errors and successes. These are the Authorization reversal request parameters:  
**Authorization Reversal Request Parameters:**

* requestID: The `Visa Acceptance for SMB` Request ID from the capture or sale.
* merchantRefCode: The `Salesforce` Order Number.
* paymentTotal: The refund amount.
* currency: Currency Code.
* refundEndpointType: 'payments' for ACH/eCheck amd 'captures' for all other payments

**Function Signature:**

```
httpRefundPayment(transactionId, referenceInformationCode, total, currency, refundEndpointType)
```

*Refunds are capped at the remaining refundable balance. A refund (whether full, a single partial, or the running total of multiple partials) that exceeds the captured amount is rejected before the gateway call.*
