Custom Money In Merchant Example

A money-in payment processing merchant is essential to taking money for orders. Although there are many providers built into the Platform, you have the power to add a custom merchant using the Client Extension.


Building a Custom Payment Processing Merchant Integration

Refer to the Pull Request below to learn how to implement a Custom Payment Processing Merchant Integration.

❗️

This code example should only be used to understand how to write an integration with a third-party Merchant. All third-party integrations should be rigorously tested to ensure that there are no defects or miscalculations as they could be very costly.

This example shows the following methods implemented with the third-party payment processor Stripe

  • The ChargePayment() Method - Required For All Saved Payment Money In Merchant Integrations
  • The RefundPayment() Method - Required For All Saved Payment Money In Merchant Integrations
  • The GetSavePaymentFrame() Method - Required For All Saved Payment Money In Merchant Integrations
  • The GetExternalPayments() Method - Optional method that can be implemented to retrieve all payment methods for a payor from the external merchant if they use a unique ID to associate cards to payors. Not all merchants associate cards to a payor in their system, but stripe does.
  • The GetNewPayerId() Method - Optional method that is invoked during checkout flows if DirectScale does not have a PayorID saved for the Active Merchant. Not all merchants associate cards to a payor in their system, but stripe does. - NOTE: If a PayorID is not assigned to the associate then the AssociateID will be used instead.

Key Take-Aways From This Example


Environment Variables

This integration utilizes environment variables to maintain different values between environments for things like keys.

The following Environment Variables are required for this integration to work:

  • StripeExtensionMerchant_PublicKey
  • StripeExtensionMerchant_PrivateKey
  • ExtensionBaseURL - used to set the URL for the SavePaymentFrame page hosted by the extension

👍

Want to run and test this integration?

Sign up for a free stripe account and get your Test API Keys

Implementing the GetSavePaymentFrame() Method

This method returns an AddPaymentFrameData class that contains the URL to a page to be displayed in a modal with an Iframe during checkout flows. This page can be hosted anywhere as long as it maintains PCI compliance.

This page must complete the following actions:

  1. Send payment information to the payment processor and retrieve a token.
  2. Post an event to the parent frame
  • With the payment metadata (Last4, CardType, Token, Etc) for the DirectScale to save the payment Info.
var data = {};
data.CardType = token.card.brand;
data.Token = token.card.id;
data.Last4 = token.card.last4;
data.ExpireMonth = token.card.exp_month;
data.ExpireYear = token.card.exp_year;

window.parent.postMessage(data, "*");
  • With a message to reload the payment methods - The Token and metadata must be saved through the Extension API before posting this event.
var data = {};
data.ReloadPaymentMethods = true;

window.parent.postMessage(data, "*");

Additional Parent Frame Events

If an error occurs when tokenizing a payment with the merchant than the error message can be posted to the parent frame with the following data.

var data = {};
data.ErrorMessage = errorMessage;

window.parent.postMessage(data, "*");

If the page has a cancel button then it can post an event to the parent frame with the following data to get the modal to close.

var data = {};
data.CloseMerchantFrame = true;

window.parent.postMessage(data, "*");