After registering and signing in April customers, Merchants can integrate the April payment source UI to capture payment sources and process card payments.
IMPORTANT
These instructions are for consumer (B2C) merchants only. Business to business (B2B) merchants should follow the B2B customer onboarding documentation.
- Register a new April customer by calling Upsert Customer with the
UpsertConsumerCustomeraction to retrieve acustomerId. - Sign in a customer by calling Sign In Customer with the
SignInCustomeraction providing thecustomerIdfrom the previous step. This will provide you with acustomToken.
Initialise the April payment source UI with a signed in customer customToken and register a submitCallbackFunction to retrieve a cardPaymentSourceId.
<script src="https://checkout-v3.au.meetapril.io/v3/checkout-v3.0.0.min.js"></script>const paymentSourceUI = window.AprilCheckout.createPaymentSource();
paymentSourceUI.init({
publicKey: 'live_pk_xxxxxxxxxxxxxxxxxxxxx', // required, merchant public key
customerToken: customToken, // signed in customer token
isB2B: false, // B2B only
hideB2BUsageScopeOptions: false, // B2B only, hide "Save card for" options
submitCallbackFunction: (paymentSource) => {
if(paymentSource.cardPaymentSource) {
// retrieve cardPaymentSourceId
const cardPaymentSourceId = paymentSource.cardPaymentSource.cardPaymentSourceId;
}
},
errorCallbackFunction: (error) => {
// handle errors
}
});
paymentSourceUI.render({
elementId: 'payment-source-container', // required, parent HTML element ID
showSubmit: true, // hide the Submit button
hideSavedCards: false, // hide previously saved cards
primaryColor: '#b29572' // theme primary color (HEX)
});WARNING
If a valid customerToken is not provided, the payment source UI will create a temporary cardPaymentSourceId that will expire in 10 minutes.
paymentSourceUI.render({
...options,
showSubmit: false // hide the Submit button
});
paymentSourceUI.submit((paymentSource) => {
if(paymentSource.cardPaymentSource) {
// retrieve cardPaymentSourceId
const cardPaymentSourceId = paymentSource.cardPaymentSource.cardPaymentSourceId;
}
});type CardPaymentSource = {
cardPaymentSourceId: string;
last4: string;
cardBin: string;
brand: '' | 'American Express' | 'MasterCard' | 'Visa';
funding: 'credit' | 'debit' | 'chargecard' | 'prepaid' | 'deferreddebit' | 'unknown';
expMonth: number;
expYear: number;
country: string;
}
type PaymentSource = {
cardPaymentSource?: CardPaymentSource;
}Merchants can also retrieve a signed in customer paymentSource from the April checkout paymentData object, as described here.
- Create a new order by calling Create Order to retrieve a
orderId. - Request a card payment by calling Create Payment Token
CreatedSavedCardTokenaction with acardPaymentSourceIdto retrieve apaymentTokenId. - Pay for an order by calling Pay Order
PayByCardaction with anorderIdandpaymentTokenId.