Use this JavaScript library to render an Apple Pay or Google Pay button. It uses the Payment Request API specified by W3C when available. If not, it falls back to the corresponding vendor implementation. This library gives you a single integration for rendering payment buttons. It can automatically detect which button should be displayed depending on the browser and device combination that is supported and used. In the demo below, depending on your device you will see either an Apple Pay or Google Pay button. Please note that for Apple Pay this library only works with a Datatrans merchantId which has been enabled for Apple Pay processing via Datatrans.
const payment = {
// W3C spec
details: {
total: {
label: 'My Merchant',
amount: { value: '4', currency: 'USD' },
},
displayItems: [
{
label: 'Tax',
amount: { value: '2.50', currency: 'USD' },
},
],
},
// W3C spec
options: {
requestPayerEmail: false,
requestPayerName: false,
requestPayerPhone: false,
},
// Datatrans specific
transaction: {
countryCode: 'CH',
refno: '3e23dasdasd1123',
},
};
<script src="https://pay.sandbox.datatrans.com/upp/payment/js/payment-button-3.0.0.js" type="text/javascript"></script>
const paymentButton = new PaymentButton();
paymentButton.init({
merchantId: '1000011011',
merchantName: 'Test',
tokenOnly: false,
autoSettle: false,
allowedCardNetworks: ['AMEX', 'DISCOVER', 'MASTERCARD', 'VISA'],
googlePayConfiguration: {
buttonType: 'long',
buttonStyle: 'black',
merchantId: '01234567890123456789'
},
applePayConfiguration: {
buttonType: 'plain',
buttonStyle: 'black'
},
});
paymentButton.on("init", function () {
paymentButton.create(document.getElementById('paybutton'), payment)
});
paymentButton.on("authorization", function (response) {
// handle transaction result
});
| Option | Description | Data type |
|---|---|---|
|
merchantId
required
|
Your Datatrans merchantId | String |
|
merchantName
required
|
Your merchant name | String |
|
allowedCardNetworks
required
|
Which card networks to accept | String array |
| useGooglePay | Use this property to disable Google Pay. Note: By default Google Pay is enabled if supported by the browser | Boolean |
| useApplePay | Use this property to disable Apple Pay. Note: Apple Pay can only be displayed in Safari browsers. Note: By default Apple Pay is enabled if supported by the browser | Boolean |
| autoSettle | Whether the transaction will be settled automatically. Default is false. | Boolean |
| googlePayConfiguration | Object | |
| buttonType | The type of button, described here | String |
| buttonStyle | The style of button, described here | String |
| merchantId | Your Google Pay merchantId. Can be found in the Google Pay merchant console | String |
| applePayConfiguration | Object | |
| buttonType | The type of button, described here | String |
| buttonStyle | The style of the button, described here | String |
| Option | Description | Data type |
|---|---|---|
|
refno
required
|
Your reference number. Find out more here | String |
|
countryCode
required
|
ISO 3166-1 alpha-2 country code where the transaction is processed.
This is required for merchants based in European Economic Area (EEA) countries.
Mandatory for payment-button v2 and v3 libraries.
|
String |
| createAlias |
Whether to create an alias.
The alias will be sent on the webhook
and is also returned through a status call.
|
Boolean |
| authenticationOnly | Only authenticate the transaction (used for deferred authorization) | Boolean |
| mcp | Configuration of Multi-Currency Pricing. Find out more here. | Object |
| amount | Object | |
| value |
Amount the customer will pay in their currency.
If you want to include fractional monetary units (pennies, cents, Rappen), you will have to
separate the amount using a decimal point (e.g. 5.10 instead of 510).
|
String |
| currency | ISO 4217 currency code of the amount the customer will pay. | String |
| provider | Identify the MCP provider used. | String |
| reasonIndicator | If received from acquirer the reason indicator can be set | String |
| conversionRate |
Rate used to calculate MCP amount.
Note: Only used in dynamic MCP
|
String | Number |
| transactionDate |
Date when the rate was fetched from the MCP provider.
Note: Only used in dynamic MCP
|
String |
| retrievalReferenceNumber |
Reference number of the MCP provider response.
Note: Only used in dynamic MCP
|
String |