Apple Pay enables Apple device owner to pay with card information securely stored by Apple without cumbersome process of filling card and payment information on website.
This example shows how you can process Apple Pay payments using our shift4.js
.
It is based on Apple Pay PaymentRequest API. If you're curious, you can find the details of the API under following locations:
The entire process is detailed in the code snippets below and can be organized into the following main sections:
shift4.js
JavaScript library [1]Apple Pay payment does not require additional 3D Secure verification.
@AjaxController
@RequestMapping("/ajax/examples/charge-with-apple-pay")
class ExamplesAjaxChargeWithApplePayWithTokenController {
@PostMapping("/payment")
Map chargeWithApplePayPayment(@RequestBody ApplePayTokenPaymentExampleRequest exampleRequest) throws IOException {
try (Shift4Gateway shift4Gateway = createShift4Gateway()) {
// create charge using received token ID
ChargeRequest chargeRequest = new ChargeRequest(100, "USD")
.paymentMethod(new PaymentMethodRequest(exampleRequest.token));
Charge charge = shift4Gateway.createCharge(chargeRequest);
// pass clientObjectId of charge to frontend
return singletonMap("clientObjectId", charge.getClientObjectId());
} catch (Shift4Exception e) {
throw new BadRequestException(e.getMessage());
}
}
static class ApplePayTokenPaymentExampleRequest {
String token;
}
}