How to implement Digital Wallets on the web through Merchant Warrior.
Before implementing Apple Pay on the web, several prerequisites must be met.
- You will need to obtain a Merchant Warrior Merchant UUID, API Key and API passphrase. These details will be issued to you when you create your MW account.
- All pages that will display the Apple Pay button must be deployed over HTTPS.
- Comply with Apple Pay Identity Guidelines and Apple Pay on the Web Human Interface Guidelines to ensure you're displaying Apple Pay properly.
- Make sure your customer's device is a compatible iPhone, iPad, Apple Watch or iMac.
- Register all domains, including both top-level domains (e.g. example.com) and sub-domains(e.g. store.example.com), that will display an Apple Pay button.
To register a domain for use with Apple Pay, you must do
- Host the domain verification file on your server. You can download the sandbox verification file here. For production, please download it here instead.
- Host the file at /.well-known/apple-developer-merchantid-domain-association on your domain(s) that will display the Apple Pay button. Apple will perform the verification automatically. For example, if your domain is https://example.com.au, host the file at https://example.com.au/.well-known/apple-developer-merchantid-domain-association. Make sure the file is publicly accessible or exclusively accessible by Apple Servers listed in Whitelist Apple IP Addresses for Domain Verification.
Before implementing Google Pay™ on the web, several prerequisites must be met.
- You will need to obtain a Merchant Warrior Merchant UUID, API Key and API passphrase. These details will be issued to you when you create your MW account.
- You will require a Merchant ID from Google. This can be obtained by creating an account via the Google Pay Business Console.
- You should provide your Google Pay Merchant ID to Merchant Warrior to save against your account.
- When you are ready to progress your web application to Production you are required by Google to Request Production Access.
- All pages that will display the Google Pay button must be deployed over HTTPS.
- Comply with the Google Pay API Terms of Service, Google Pay APIs Acceptable Use Policy, and Google's Brand Guidelines.
The easiest way to integrate Apple Pay and other wallets is to use the Merchant Warrior Web SDK.
- Include the Merchant Warrior Javascript in the head of your HTML document
<script src="https://securetest.merchantwarrior.com/sdk/merchantwarrior.min.js"></script>
- Configure your options
const merchantUUID = '12345abcde';
const apiKey = 'abc123';
const options = {
environment: 'development', // Default value is 'production'
middleware: '/.well-known/MerchantWarrior.php',
xcsrfToken: '<Session Verification Data>',
}
-
Configure your middleware. For security reasons, the JavaScript SDK does not make any calls directly to the Merchant Warrior servers. Rather, these requests are passed through a middleware option. Please see our guide on how to set up your middleware.
-
Create the Merchant Warrior object. This can be done in one of two ways -
4A. The static MerchantWarrior.create() method will return a promise containing the object pre-populated with your merchant information.
MerchantWarrior.create(merchantUUID, apiKey, options).then((mwarrior) => {
// Interact with the mwarrior object here
});
4B. The static MerchantWarrior.createWithToken() method can alternatively be used to to create the promise using an accessToken instead of your merchant credentials.
MerchantWarrior.createWithToken(accessToken, options).then((mwarrior) => {
// Interact with the mwarrior object here
});
- Create a payment summary. If the customer details are currently unknown, they can be omitted and supplied later in the process. This summary also allows you to choose which wallets you would like to be made available to compatible devices. The options are
googlepay
,applepay
, andbasic-card
.basic-card
uses whatever interface the browser makes available, and uses card data (such as PAN) directly.
The applePay
property is for specific Apple Pay options. It takes an object that has a single string property, buttonText
. This property controls what text is displayed on the Apple Pay button. Available options include buy
, donate
, plain
, set-up
, book
, check-out
, subscribe
, add-money
, contribute
, order
, reload
, rent
, support
, tip
, or top-up
.
The googlePay
property is for specific Google Pay options. It takes an object with 4 properties; buttonText
, buttonLocale
, buttonHeight
and buttonWidth
.
- The
buttonText
property has the following available options:book
,buy
,checkout
,donate
,order
,pay
,plain
,subscribe
. buttonLocale
accepts any locale, eg.en
orfr
buttonHeight
andbuttonWidth
accept dimensions in pixels
const customer = {
name: 'Jane Doe',
country: 'AU',
state: 'QLD',
city: 'Brisbane',
address: '345 Ann Street',
postCode: '4000',
phone: '61412345678'
}
const transaction = {
transactionReferenceID: "ref1234",
storeID: "store123",
custom1: "one",
custom2: "two",
custom3: "three",
currency: "AUD"
}
const summary = {
total: {
amount: '25.00',
label: 'A Product',
pending: false
},
transaction: transaction, // optional
customer: customer,
style: 'dark', // Optional - default dark
applePay: {
buttonText: 'buy'
},
googlePay: {
buttonText: 'buy',
buttonLocale: 'en',
buttonHeight: '45px',
buttonWidth: '100px'
},
wallets: [
'googlepay',
'applepay',
],
}
- Create and mount a payment request
mwarrior.paymentRequest(summary).then((element) => {
element.mount('payment-buttons'); // This will attach the buttons to the HTML element with an id of 'payment-buttons'
});
- Handle events.
The two primary events
-
payment-complete
, which will trigger when the payment process has completed. It has 3 arguments,status
which is a boolean value indicating whether the payment was successful,response
which contains a JSON object detailing the response from the Merchant Warrior servers, anderrors
which contains any Javascript error details. Whether a payment is successful or not, the button that triggered it will still be reusable and should be manually removed when finished with. -
request-customer
, which will trigger near the start of the payment flow if a customer is not included in the initial payment summary. It has two parameters - resolve, and reject. These are connected to an internal promise. Calling theresolve
parameter with a valid customer will allow the payment request to proceed, and calling thereject
parameter will end the payment and trigger thepayment-complete
event.
mwarrior.on('payment-complete', (status, response, errors) => {
if (status) {
document.getElementById('payment-buttons').innerHTML = '';
// Payment successful!
} else {
// Payment failed
}
});
mwarrior.on('request-customer', (resolve, reject) => {
resolve(customer);
});
- Put it all together. An example of this code in action can be found here
const merchantUUID = '12345abcde';
const apiKey = 'abc123';
const options = {
environment: 'development', // Default value is 'production'
}
const transaction = {
transactionReferenceID: "ref1234",
storeID: "store123",
custom1: "one",
custom2: "two",
custom3: "three",
currency: "AUD"
}
const summary = {
total: {
amount: '25.00',
label: 'A Product',
pending: false
},
transaction: transaction, // optional
customer: customer,
style: 'dark', // Optional - default dark
applePay: {
buttonText: 'buy'
},
googlePay: {
buttonText: 'buy',
buttonLocale: 'en',
buttonHeight: '45px',
buttonWidth: '100px'
},
wallets: [
'googlepay',
'applepay',
],
}
MerchantWarrior.create(merchantUUID, apiKey, options).then((mwarrior) => {
mwarrior.paymentRequest(summary).then((element) => {
element.mount('payment-buttons'); // This will attach the buttons to the HTML element with an id of 'payment-buttons'
});
mwarrior.on('payment-complete', (status, response, errors) => {
if (status) {
document.getElementById('payment-buttons').innerHTML = '';
// Payment successful!
} else {
// Payment failed
}
});
mwarrior.on('request-customer', (resolve, reject) => {
const customer = {
name: 'Jane Doe',
country: 'AU',
state: 'QLD',
city: 'Brisbane',
address: '345 Ann Street',
postCode: '4000',
phone: '61412345678'
}
resolve(customer);
});
To integrate manually, follow the instructions provided by Apple and Google, and include the final token in a Digital Wallet processCard request.