REST API services for Apple Pay on the Web

The Accelerator assets contain manual updates to the backend payment system and WebSphere Commerce REST API to ensure that Apple Pay on the Web works correctly.

ApplePayHandler is a new resource handler that contains all the REST services that are created for Apple Pay on the Web. This resource handler is available in the following location.

com.ibm.commerce.applepay.rest.handler.ApplePayHandler
Table 1. Backend services code
REST service name Description REST service
Create Apple Pay order If a shopper clicks the apple pay button from product display page, the create apple pay order creates a new pending order for this shopper. The apple pay order can be created by using the existing order service and by passing the parameter as orderId=**. POST store/{storeId}/cart/@self
Prepare Apple Pay order The prepare Apple Pay order service is called before rendering the payment sheet, this service is implemented by ApplePayOrderPrepareCmd service.
  1. The Apple Pay order prepare service handles the payment-based promotions that are enabled. The unbound payment instruction is also added. (Unbound payment instruction is a dummy payment instruction that is created for promotion only, it will be removed later.)
  2. The Apple Pay order prepare service calls OrderPrepareCmd to recalculate the Apple Pay order and processes the inventory logic.
POST store/{storeId}/applepay/cart/prepare
Get Order information Get order service is called after ApplePayPrepare. It retrieves the data that is provided to payment sheet, including the order and order items details, such as the order total, discount, shipping, tax,. Get order service retrieves the available shipping addresses and shipping methods. For each shipping method, it gets the shipping charge for each shipping method. A new implementation class ComposeUsableShippingInfoWithShippingChargeCmdImpl is created for access profiles such as IBM_UsableShippingInfo. In this new class, it composes the available shipping method and the shipping charge for each shipping method.
  • GET store/{storeId}/cart/@self
  • GET store/{storeId}/cart/@self/usable_shipping_info
Merchant validation Merchant validation is required for every Apple Pay on the Web session. It is used to ensure that your site is secure and available for Apple Pay. It first gets the merchant validation URL from Safari, then gets the merchant session from Apple Pay's server in the backend, and passes the merchant session object to ApplePayJS. POST store/{storeId}/applepay/merchant/validate
Update Apple Pay Order Apple Pay order update service is called by onshippingcontactselected event or onshippingmethodselected event, which is when shopper update the shipping address, contact or shipping method. The apple pay order item's addressId or shimodeId is updated in the service. This service is implemented by the ApplePayOrderUpdateCmd command. PUT: store/{storeId}/applepay/cart
Process Apple Pay Order The Apple Pay order process service is called by onpaymentauthorized callback function. This service is implemented by the ApplePayOrderProcessCmd command, which includes the following logic:
  • Removes the unbound payment instruction, if present.
  • Handles the shipping and billing address.
  • Calls OrderProcessCmd to submit this order, which triggers the PrimePayment event in the Payment subsystem and corresponding payment processing logic will be run.
POST: store/{storeId}/applepay/cart/process
Cancel Apple Pay order The Cancel Apple Pay order service is called by the oncancel callback function. This service is implemented by the ApplePayOrderCancelCmd command, which includes the following logic:
If the Apple Pay request is sent from the product details page:
  • Delete the new created order and it’s order items.
  • Delete the address of the order item if it was a dummy address.
If the Apple Pay request is sent from the shopping cart or mini shop cart page:
  • Delete the address of the order item if it was a dummy address.
POST: store/{storeId}/applepay/cart/cancel
Payment Service Provider interaction Payment Service Provider (PSP) interaction is handled by the com.ibm.commerce.applepay.payment.commands.ProcessApplePayPaymentCmd task command.

This task command is invoked by the WebSphere Commerce Payment subsystem to respond to the PrimePayment event triggered by OrderProcessCmd. A new Apple Pay payment plug-in is used in WebSphere Commerce to support the Apple Pay payment method for Apple Pay on the Web. This Apple Pay plug-in invokes the ProcessApplePayPaymentCmd command to process the interaction with the Payment Service Provider that supports Apple Pay.

You must implement the ProcessApplePayPaymentCmd command to interact with your Payment Service Provider. In this command implementation, you typically can either decrypt the payment token and pass the RAW data to your PSP, or forward the encrypted payment token to your PSP directly, depending on the Payment Service Provider's requirements.

In the sample assets, a dummy implementation for ProcessApplePayPaymentCmd (com.ibm.commerce.applepay.payment.commands.ProcessApplePayPaymentCmdImpl) is provided for testing purposes. It logs the payment token and mocks the PSP to return a successful payment processing result.