---
schema_version: "1"
id: c93aef9618a6ff14b1cfbaf8fa2446598ce351b9d355cd1b92bf798180d551de
title: Payment Service Provider
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/commerce-cloud/b2c-commerce/guides/customer-service-center/b2c-csc-psp.md
canonical_url: https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/b2c-csc-psp.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 318997289d19422faa77107d2c5a5c6ca1853aa7de0274a46abba5d8a17ceb3d
products:
  - Composable Storefront
  - Salesforce APIs
---
# Payment Service Provider

For the Payment Service Provider (PSP) integration to work properly in Customer Service Center, Shop API interactions require code to connect Customer Service Center with the B2C Commerce PSP cartridge. To add or update a payment method after each event in Customer Service Center, “dw.order.hooks.PaymentHooks” is called within an encapsulated transaction.

To register a payment hook, complete the following registration.

```json
{
  "hooks": [
    { "name": "dw.order.payment.authorize", "script": "./authorize.js" },
    { "name": "dw.order.payment.authorizeCreditCard", "script": "./authorize.js" }
  ]
}
```

## Example

To initiate the authorize logic in the PSP cartridge, include the code in `authorize.js`.

```javascript
importPackage(dw.system);
importPackage(dw.order);
importPackage(dw.value);
importPackage(dw.util);

function authorize(order: Order, paymentDetails: OrderPaymentInstrument) {
  //link your payment cartridge here...
  Logger.info("auth for order {0}", order.orderNo);
  var gcCode: String = paymentDetails.getGiftCertificateCode();
  Logger.info("GC Code {0}", paymentDetails.getGiftCertificateCode());

  if (gcCode == "bad") {
    return new Status(
      Status.ERROR,
      "ERR_BAD",
      "The Gift Certificate {0} could not authorized successfully.",
      gcCode,
    );
  }

  return new Status(Status.OK);
}

function authorizeCreditCard(order: Order, paymentDetails: OrderPaymentInstrument, cvn: String) {
  //link your payment cartridge here...
  var ccno: String = paymentDetails.getCreditCardNumber();
  Logger.info(
    "CC payment auth for order {0} - {1}",
    order.orderNo,
    "************" + ccno.substr(12),
  );

  if (ccno == "4111111111112222") {
    Logger.info(
      "=====================================ERROR===========================================",
    );
    return new Status(
      Status.ERROR,
      "ERR_2222",
      "Creditcard ending with {0} could not be authorized. Error code: {1}.",
      ccno.substr(12),
      "ERR_2222",
    );
  }

  return new Status(Status.OK);
}

module.exports = {
  authorize: authorize,
  authorizeCreditCard: authorizeCreditCard,
};
```
