Constructor
new TranspayrentApplePayHelper(environment, config, transaction)
Creates a new instance of the Transpayrent SDK, which uses the Transpayrent Helper SDK for Apple Pay internally to abstract the Apple Pay Javascript Client.
Parameters:
Name | Type | Description |
---|---|---|
environment |
String | The Apple Pay environment, either PRODUCTION or TEST, that will be used by the helper SDK |
config |
ApplePayConfig | The base configuration for Apple Pay. |
transaction |
ApplePayTransaction | The details for the payment transaction that will be authorized using Apple Pay |
- Version:
- 1.0.3
- Copyright:
- Transpayrent ApS 2022
- License:
- Common Transpayrent API license
- Source:
- See:
Example
<script src="https://storage.googleapis.com/static.[ENVIRONMENT].transpayrent.cloud/v1/swagger-client.js"></script>
<script src="https://storage.googleapis.com/static.[ENVIRONMENT].transpayrent.cloud/v1/transpayrent.js"></script>
<script>
// SDK configuration
var transpayrentConfig = {
merchantId: [UNIQUE MERCHANT ID ASSIGNED BY TRANSPAYRENT],
sessionId: [ID IN THE RESPONSE FROM "Create Payment Session"],
accessToken: '[x-transpayrent-access-token HTTP HEADER IN THE RESPONSE FROM "Create Payment Session"]'
};
var url = 'https://generator.[ENVIRONMENT].transpayrent.cloud/v1/'+ transpayrentConfig.merchantId +'/system/PAYMENT_GATEWAY/sdk/CLIENT';
// Instantiate SDK
var sdk = new Transpayrent(url, transpayrentConfig);
// List of payment methods supported by Apple Pay as returned in the response from "Create Payment Session"
const paymentMethodIds = [ 103, // VISA Dankort
107, // Maestro
108, // MasterCard
109, // VISA
110 // VISA Electron
];
// Display the Payment Sheet for Apple Pay
var config = { buttonstyle : 'black',
type : 'pay',
locale : 'en',
onClick : () => {
const paymentMethodId = 204; // Apple Pay
var paymentSheetDetails = { merchant_id : transpayrentConfig.merchantId,
merchant_name : '[MY MERCHANT]',
country : 208, // Denmark
payment_method_ids : paymentMethodIds,
amount : { currency : 208, // DKK
value : 1000 },
save : false };
sdk.displayPaymentSheet(paymentMethodId, paymentSheetDetails)
.then(token => completePayment(paymentMethodId) )
.catch(reason => {
document.getElementById('container').style.visibility = 'hidden';
alert('API: '+ reason.api +' failed with HTTP Status Code: '+ reason.status +' and error: '+ reason.messages[0].message +'('+ reason.messages[0].code +')');
});
} };
// Display the "Buy with Apple Pay" button
sdk.displayPaymentButton(204, document.getElementById('apple-pay-button-container'), paymentMethodIds, config);
</script>
Methods
displayPaymentButton(container, paymentMethodIds, config, …args)
Displays the Apple Pay payment button after confirmation of the viewer's ability to pay.
It is strongly recommended to use Transpayrent#displayPaymentButton.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
container |
* | ||
paymentMethodIds |
Array.<PAYMENT_METHOD_ID> | List of Payment IDs returned by the Transpayrent Gateway upon initializing the payment transaction |
|
config |
* | ||
args |
any |
<repeatable> |
displayPaymentSheet(sdk, resolver, rejecter)
Show Apple Pay payment sheet when Apple Pay payment button is clicked.
It is strongly recommended to use Transpayrent#displayPaymentSheet.
Parameters:
Name | Type | Description |
---|---|---|
sdk |
Transpayrent | An instance of the Transpayrent Browser SDK, which may be used to interact with the Transpayrent Payment Gateway |
resolver |
function | The resolver function for a promise |
rejecter |
function | The rejecter function for a promise |