canMakePayment Function
The canMakePayment function checks whether payment is possible according to your merchant configuration, client software (OS version and browser), and hardware support. Call it before the showButtons function to catch potential problems that might make the latter function – and subsequent payment – fail. If payment is not possible, it gives you the opportunity to take some other action, such as offering the customer an alternative payment method.
The function signature is as follows:
paysafe.request.canMakePayment(callback);
The function parameters are described below.
Required | Type | Description | ||
callback | true | function(methods, error) {...} | Contains the supported payment methods, which, in turn, depend on:
| |
methods | N/A | string array | List of all supported payment methods. For example: ["APPLEPAY"] | |
error | N/A | object | Error object indicating failure reason: 9013, 9077, 9080, 9084, 9085, 9086 A null value indicates success: payment is possible. | |
{throws} | N/A | Throws an exception with the following errors: 9004, 9014, 9067. | ||
{return} | false | undefined |
Apple Pay Example
This example in the TEST environment uses the canMakePayment function to check whether payment is possible before calling onTokenization and showButtons.
<html>
<head>
<script type="text/javascript" src="https://hosted.paysafe.com/request/v1/latest/paysafe.request.min.js"></script>
</head>
<body>
...
<div id="x-paysafe-apple-pay-button"></div>
...
<script>
paysafe.request.init("my API key", {
country: "US",
currency: "USD",
amount: 1234,
label: "My label",
environment: "TEST"
});
paysafe.request.canMakePayment(function (methods, error) {
if (methods) {
if (methods.indexOf("APPLEPAY") < 0) {
// Apple pay not supported
} else {
paysafe.request.onTokenization(function (event, error) {
if (event) {
// Process the token - event.result.token
// Acknowledge - event.showSuccess() or reject event.showFailure()
event.showSuccess();
} else {
// handle error
}
});
paysafe.request.showButtons(function (displayedPaymentMethods, error) {
if (error) {
// handle error
}
});
}
} else {
// handle error
}
});
</script>
</body>
</html>