Apple Pay: Difference between revisions

From Barion Documentation
Jump to navigation Jump to search
Line 38: Line 38:


== Development ==
== Development ==
# Include the Apple Pay SDK
=== Include the Apple Pay SDK===
#: Include the following code snippet in the header of your checkout page:
Include the following code snippet in the header of your checkout page:
#: <code><script src="https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js"></script></code>
<code><script src="https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js"></script></code>
# Display the Apple Pay button
===Display the Apple Pay button===
#: Add the Apple Pay button to your checkout page as discussed [https://developer.apple.com/documentation/apple_pay_on_the_web/displaying_apple_pay_buttons_using_javascript here]
Add the Apple Pay button to your checkout page as discussed [https://developer.apple.com/documentation/apple_pay_on_the_web/displaying_apple_pay_buttons_using_javascript here]
# Create an Apple Pay session
===Create an Apple Pay session===
#: When the user taps the Apple Pay button, provide a payment request and create the session as discussed [https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session here]
When the user taps the Apple Pay button, provide a payment request and create the session as discussed [https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/creating_an_apple_pay_session here]
# Subscribe to the <code>[https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778021-onvalidatemerchant onvalidatemerchant]</code> event
===Subscribe to the <code>[https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778021-onvalidatemerchant onvalidatemerchant]</code> event===
#: Call our [[ApplePay-ValidateSession|ValidateSession]] endpoint in the event handler with the provided url as the payload
Call our [[ApplePay-ValidateSession|ValidateSession]] endpoint in the event handler with the provided url as the payload
#: <code>
<syntaxhighlight lang="javascript">appleSession.onvalidatemerchant = function (event) {
#: </code>
            // TODO: disable Apple Pay button
# Call <code>ApplePaySession.begin</code> method
            ap.settings.requestSession(event.validationURL,
#: Call the [https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778001-begin begin] method, and the merchant validation process begins
                function (merchantSession) {
                    // success callback
                    appleSession.completeMerchantValidation(merchantSession);
                },
                function() {
                    // failure callback
                    // TODO: enable Apple Pay button
                }
            );
        };</syntaxhighlight >
===Call <code>ApplePaySession.begin</code> method===
Call the [https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778001-begin begin] method, and the merchant validation process begins


== API reference ==
== API reference ==
* [[ApplePay-ValidateSession|/v2/ApplePay/ValidateSession]]
* [[ApplePay-ValidateSession|/v2/ApplePay/ValidateSession]]
* [[ApplePay-StartPaymentWithAppleToken|/v2/ApplePay/StartPaymentWithAppleToken]]
* [[ApplePay-StartPaymentWithAppleToken|/v2/ApplePay/StartPaymentWithAppleToken]]

Revision as of 18:47, 1 December 2021

Apple Pay integration

NOTE
We currently only support Apple Pay for the web, native iPhone app support is coming soon.

Introduction

Apple Pay can be emebedded two ways into your payment flow. In the first case, it will be displayed on Barion Smart Gateway, which needs no further development on your side, however you should request it from Customer Care through the ticketing. The second option is to display the Apple Pay button on your site ("integrated mode"), however this needs configuration and development on your side. This page will discuss the latter.

Limitations

Using Apple Pay as a token payment is currently not possible.

Apple Pay will be visible to shoppers fulfilling the following criteria:

Moreover the shop must not provide prohibited items by Apple

Prerequisits

  • you must have a Barion wallet
  • the beforementioned Barion wallet must have and approved shop
  • For every currency you plan to conduct payments in you have to make sure there is an account created in your Barion wallet. This means that if you plan to have USD payments then there should be an USD account created in your wallet.

Configuration

  1. Domain verification file
    First head over to secure.barion.com, and under Manage My Shops page select the appropriate one, and from the dropdown, click on settings. At the bottom click the Manage Apple Pay settings blue button under the Apple Pay Settings section. On the next page Click on the Download domain verification file button, which will download a domain association file. You should place this file at the content root of all of your sites, you're about to use apple pay in integrated mode.
    The file must:
    • Have Content-Type: text/plain in the header.
    • Be externally accessible.
    • Not be password protected.
    • The file cannot be behind a proxy or redirect.
  2. Configure Domains
    On the exact same page you've downloaded the domain association file, enter all the domains (one in each line, without https:// or https://) you're intending to use Apple Pay.
  3. Request Apple Pay to be enabled
    Head over to the Customer Center, and request Apple Pay to be enabled for your shop.

Development

Include the Apple Pay SDK

Include the following code snippet in the header of your checkout page: <script src="https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js"></script>

Display the Apple Pay button

Add the Apple Pay button to your checkout page as discussed here

Create an Apple Pay session

When the user taps the Apple Pay button, provide a payment request and create the session as discussed here

Subscribe to the onvalidatemerchant event

Call our ValidateSession endpoint in the event handler with the provided url as the payload

appleSession.onvalidatemerchant = function (event) {
            // TODO: disable Apple Pay button
            ap.settings.requestSession(event.validationURL,
                function (merchantSession) {
                    // success callback
                    appleSession.completeMerchantValidation(merchantSession);
                },
                function() {
                    // failure callback
                    // TODO: enable Apple Pay button
                }
            );
        };

Call ApplePaySession.begin method

Call the begin method, and the merchant validation process begins

API reference