How to Implement Apple Pay on Web and Mobile Apps


On this page

Apple Pay on the Web

1- Check availability and Display an Apple Pay button.

From your frontend, check Apple Pay JS availability and that browser supports Apple Pay.

if (window.ApplePaySession) {
   let merchantIdentifier = 'example.com.store';
   let promise = ApplePaySession.canMakePaymentsWithActiveCard(merchantIdentifier);
   promise.then(function (canMakePayments) {
      if (canMakePayments)
         // Display Apple Pay button here.
});
}

2- Create a Payment Request (Initiate session)

When the buyer clicks on the button, create an ApplePaySession object with the required properties to display the payment sheet: the total amount, the currency, and the supported payment networks. Along with the Apple Pay version.

let paymentRequest = {
    currencyCode: 'SAR',
    countryCode: 'SA',
    lineItems: [],
    total: {
        label: "Mystore shop",
        amount: 1
    },
    supportedNetworks: ['masterCard', 'visa', 'mada'],
    merchantCapabilities: ['supports3DS', 'supportsCredit', 'supportsDebit']
};
var session = new ApplePaySession(6, paymentRequest);

3- Complete Merchant Validation

In this step you are validating your merchant identity and receiving a session object for each payment request.

First you need to call onvalidatemerchant event handler and get event.validationURL event attribute to pass it to your server endpoint for merchant validation.

An example of how you can do this is shown below: (XMLHttpRequest)

session.onvalidatemerchant = function (event) {
    let promise = performValidation(event.validationURL);
    promise.then(function (merchantSession) {
        session.completeMerchantValidation(merchantSession);
    }).catch((error) => console.log(error));
}
function performValidation(valURL) {
    return new Promise(function(resolve, reject) {
        let xhr = new XMLHttpRequest();
        let data = JSON.stringify({"validationURL":valURL});
        xhr.onload = function() {
            let data = JSON.parse(this.responseText);
            resolve(data);
        };
        xhr.onerror = reject;
        xhr.open('POST', '/apple_pay_merchant_validation');
        xhr.send(data);
    });
}

Then, your backend endpoint will POST to the validation URL to validate you as a merchant and request an Apple Pay session from Apple Pay servers, as follows:

php example

$certificatePassphrase = '<you_passphrase>';
$merchantIdentifier = '<your_merchant_id>';
$validationUrl = '<validationURL_from_ajax_call>';
$certificateKey = '<path_to_ApplePay.key.pem';
$certificate = '<path_to_ApplePay.crt.pem';
$domainName = '<your_domain>;
$data = '{"merchantIdentifier":"'.$merchantIdentifier.'", "domainName":"'.$domainName.'", "displayName":"<your_store_name>"}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_URL, $validationUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSLCERT, $certificate);
curl_setopt($ch, CURLOPT_SSLKEY, $certificateKey);
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $certificatePassphrase);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;

ruby (rails) example

require 'net/http'
require 'uri'

  def get_session
    uri = URI.parse(params[:validationURL])
    data = {"merchantIdentifier" => "<your_merchant_id>",  "domainName" => "<your_domain_namr>",  "displayName" => "<your_store_name>"}
    pem = File.read '<path_to_ApplePay.crt.pem>'
    key = File.read '<path_to_ApplePay.key.pem>'
    passphrase = '<passphrase>'
    http = Net::HTTP.new uri.host, uri.port
    http.use_ssl = true
    http.ssl_version = :TLSv1_2
    http.ciphers = ['ECDHE-RSA-AES128-GCM-SHA256']
    http.cert = OpenSSL::X509::Certificate.new pem
    http.key = OpenSSL::PKey::RSA.new key, passphrase
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    request = Net::HTTP::Post.new uri.request_uri, 'Content-Type' => 'text/json'
    request.body = data.to_json
    response = http.request(req)
    ....
  end

4-Complete payment authorization

After you successfully completed merchant validation, in this step you are ready to extract the payment token (from your frontend) and send it to Moyasar.

call onpaymentauthorized event handler to extract the payment token from the event attribute event.payment.token. Stringify the value of event.payment.token.paymentData then send it to Moyasar to complete the payment.

An example of Apple Pay Payment Token:

{
   "paymentData":{
      "data":"4t0A+GFsVZ6BQhqr9KGnQazrW2G2V6j0X3qbx9MMCdr+s7MicdiURN472m1eQFhwPK58MFaiuufbA0AQUTb/cZaxktBpS3EhBFaSbmh/X+EuzIY4Vh++Vt5kXmoUY9VwDJ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AAAAAAAAA==",
      "header":{
         "publicKeyHash":"Bw2jd/MOcWGckejernjkTIq7mHTAQNWQKcq1gWcIXa7QM=",
         "ephemeralPublicKey":"MFkwEwYHKkejkfjcekr0DAQcDQgAEph3VTEk5p2MRTZp/VvPW6kj/A48iPL7B9kyEfUVlvI649kEch/+8XGsVtLaDe9oLjc9NY44JbuU1WKdcirujzw==",
         "transactionId":"8afa0035a55ca99004943nh55923hc99f799a61d3997cf8c1463fc6a36d2ad4ad78"
      },
      "version":"EC_v1"
   },
   "paymentMethod":{
      "displayName":"mada 2514",
      "network":"mada",
      "type":"debit"
   },
   "transactionIdentifier":"8afa0035a55ca99004943nh55923hc99f799a61d3997cf8c1463fc6a36d2ad4ad78"
}

An example of how you can complete this step

session.onpaymentauthorized = function (event) {
        var promise = sendPaymentToken(event.payment.token.paymentData);
        promise.then(function (success) {
            var status;
            if (success) {
                status = ApplePaySession.STATUS_SUCCESS;
            } else {
                status = ApplePaySession.STATUS_FAILURE;
            }
            session.completePayment(status);
        }).catch(function (e) {
            console.log(e)
        });
    }
function sendPaymentToken(paymentToken) {
    return new Promise(function (resolve, reject) {
        // here you either send the token from your frontend (XMLHttpRequest, jQuery..) or backend (PHP, Ruby..) to Moyasar.
        // examples for this request are listed in the tabs below.
    })
}

Examples of Moyasar request:

POST /v1/payments HTTP/1.1
Host: api.moyasar.com
Content-Type: application/json
Authorization: Basic cGtfbGl2ZV9USDZyVmVQR0dsEEGSdER0b0oxTHNSZmVLWW92WmdDMXVkZGg3TmRYOg==
Content-Length: 3950

{
"amount":100,
"description": "apple pay request example",
"source":{
    "type":"applepay",
    "token": {
        "data":"4t0A+GFsVZ6BQhqr9KGnQazrW2G2V6j0X3qbx9MMCdr+s7MicdiURN472m1eQFhwPK58MFaiuufbA0AQUTb/cZaxktBpS3EhBFaSbmh/X+EuzIY4Vh++Vt5kXmoUY9VwDJw/yfFGvS29eIOHR6VKLhsNL1sm/u/qmo+tcvJAqtpQXQJStrWjUapnIz9U0Ze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cq1gWcIXa7QM=",
            "ephemeralPublicKey":"MFkwEwYHKkejkfjcekr0DAQcDQgAEph3VTEk5p2MRTZp/VvPW6kj/A48iPL7B9kyEfUVlvI649kEch/+8XGsVtLaDe9oLjc9NY44JbuU1WKdcirujzw==",
            "transactionId":"8afa0035a55ca99004943nh55923hc99f799a61d3997cf8c1463fc6a36d2ad4ad78"
        },
        "version":"EC_v1"
    }
},
}

 curl --location --request POST 'https://api.moyasar.com/v1/payments' \
 --header 'Content-Type: application/json' \
 --user 'pk_live_nwC516XHiZn5TLSskHX2sWQtW8Hveuau6fCCQEXH:' \
 --data-raw '{
    "amount":100,
    "description": "apple pay request example",
    "source":{
        "type":"applepay",
        "token": {
            "data":"4t0A+GFsVZ6BQhqr9KGnQazrW2G2V6j0X3qbx9MMCdr+s7MicdiURN472m1eQFhwPK58MFaiuufbA0AQUTb/cZaxktBpS3EhBFaSbmh/X+EuzIY4Vh++Vt5kXmoUY9VwDJw/yfFGvS29eIOHR6VKLhsNL1sm/u/qmo+tcvJAqtpQXQJStrWjUapnIz9U0ZeLoQSdtIvd0ihtVpq76spHFuom3yOoSVmFcX/X89vTTcdW0itRcve9pTOIsw+z+hGxgsmTaZF/ZgM6rPQgBfUZqDgsTMd/gWcBUIxtxUhA6/Dyzcm590w01kcKtwNzfepMuiElqvQ7Gu30vch3b6JtQhQs3Mr/BvPJOKRjpV+9fz6vBS55tmFVVTGmXKW5SWWfZiYy8tsxr0OEIdHMxf2cSE80=",
            "signature":"MIAGCSqGSIb3DQEHAEFADCABgkqhkiG9w0BBwEAAKCAMIID4zCCA4igAwIBAgIITDBBSVGdVDYwCgYIKoZIzj0EAwIwejEuMCwGA1UEAwwlQXBwbGUgQXBwbGljYXRpb24gSW50ZWdyYXRpb24gQ0EgLSBHMzEmMCQGA1UECwwdQXBwbGUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxEzARBgNVBAoMCkFwcGxlIEluYy4xCzAJBgNVBAYTAlVTMB4XDTE5MDUxODA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gYYwejEuMCwGA1UEAwwlQXBwbGUgQXBwbGljYXRpb24gSW50ZWdyYXRpb24gQ0EgLSBHMzEmMCQGA1UECwwdQXBwbGUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxEzARBgNVBAoMCkFwcGxlIEluYy4xCzAJBgNVBAYTAlVTAghMMEFJUZ1UNjANBglghkgBZQMEAgEFAKCBlTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0yMTAzMTQwODUzMDVaMCoGCSqGSIb3DQEJNDEdMBswDQYJYIZIAWUDBAIBBQChCgYIKoZIzj0EAwIwLwYJKoZIhvcNAQkEMSIEICPZfeIzu2S+cIEUuBE8hAj4r0p8sLuTmJAmjRkh3kihMAoGCCqGSM49BAMCBEcwRQIga52wabSNeoid67HRQcA6gYRXFbQxEOLc9+8dw13sQqcCIQDu8deNzrNjw0IZtSNKggxAuBah6vlU3jV7g/KP5NYU+AAAAAAAAA==",
            "header":{
                "publicKeyHash":"Bw2jd/MOcWGckejernjkTIq7mHTAQNWQKcq1gWcIXa7QM=",
                "ephemeralPublicKey":"MFkwEwYHKkejkfjcekr0DAQcDQgAEph3VTEk5p2MRTZp/VvPW6kj/A48iPL7B9kyEfUVlvI649kEch/+8XGsVtLaDe9oLjc9NY44JbuU1WKdcirujzw==",
                "transactionId":"8afa0035a55ca99004943nh55923hc99f799a61d3997cf8c1463fc6a36d2ad4ad78"
            },
            "version":"EC_v1"
        }
    },

 }'

 var settings = {
  "url": "https://api.moyasar.com/v1/payments",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Content-Type": "application/json",
    "Authorization": "Basic " + btoa("pk_live_nwC516XHiZn5TLSskHX2sWQtW8Hveuau6fCCQEXH" + ":")
  },
  "data": JSON.stringify({"amount":100,"description":"apple pay request example","source":{"type":"applepay","token":
        JSON.stringify({
                               "data":"4t0A+GFsVZ6BQhqr9KGnQazrW2G2V6j0X3qbx9MMCdr+s7MicdiURN472m1eQFhw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gYRXFbQxEOLc9+8dw13sQqcCIQDu8deNzrNjw0IZtSNKggxAuBah6vlU3jV7g/KP5NYU+AAAAAAAAA==",
                               "header":{
                                   "publicKeyHash":"Bw2jd/MOcWGckejernjkTIq7mHTAQNWQKcq1gWcIXa7QM=",
                                   "ephemeralPublicKey":"MFkwEwYHKkejkfjcekr0DAQcDQgAEph3VTEk5p2MRTZp/VvPW6kj/A48iPL7B9kyEfUVlvI649kEch/+8XGsVtLaDe9oLjc9NY44JbuU1WKdcirujzw==",
                                   "transactionId":"8afa0035a55ca99004943nh55923hc99f799a61d3997cf8c1463fc6a36d2ad4ad78"
                               },
                               "version":"EC_v1"
                           })),
 };

 $.ajax(settings).done(function (response) {
  console.log(response);
 });


var axios = require('axios');
var data = JSON.stringify({"amount":100,"description":"apple pay request example","source":{"type":"applepay","token":
                   JSON.stringify({
                                          "data":"4t0A+GFsVZ6BQhqr9KGnQazrW2G2V6j0X3qbx9MMCdr+s7MicdiURN472m1eQFhwPK58MFaiuufbA0AQUTb/cZaxktBpS3EhBFaSbmh/X+EuzIY4Vh++Vt5kXmoUY9VwDJw/yfFGvS29eIOHR6VKLhsNL1sm/u/qmo+tcvJAqtpQXQJStrWjUapnIz9U0ZeLoQSdtIvd0ihtVpq76spHFuom3yOoSVmFcX/X89vTTcdW0itRcve9pTOIsw+z+hGxgsmTaZF/ZgM6rPQgBfUZqDgsTMd/gWcBUIxtxUhA6/Dyzcm590w01kcKtwNzfepMuiElqvQ7Gu30vch3b6JtQhQs3Mr/BvPJOKRjpV+9fz6vBS55tmFVVTGmXKW5SWWfZiYy8tsxr0OEIdHMxf2cSE80=",
                                          "signature":"MIAGCSqGSIb3DQEHAEFADCABgkqhkiG9w0BBwEAAKCAMIID4zCCA4igAwIBAgIITDBBSVGdVDYwCgYIKoZIzj0EAwIwejEuMCwGA1UEAwwlQXBwbGUgQXBwbGljYXRpb24gSW50ZWdyYXRpb24gQ0EgLSBHMzEmMCQGA1UECwwdQXBwbGUgQ2VydG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DIt1UQhsKMFd2xd8zg7kGf9F3wsIW2WT8ZyaYISb1T4en0bmcubCYkhYQaZDwmSHQAAMYIBjDCCAYgCAQEwgYYwejEuMCwGA1UEAwwlQXBwbGUgQXBwbGljYXRpb24gSW50ZWdyYXRpb24gQ0EgLSBHMzEmMCQGA1UECwwdQXBwbGUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxEzARBgNVBAoMCkFwcGxlIEluYy4xCzAJBgNVBAYTAlVTAghMMEFJUZ1UNjANBglghkgBZQMEAgEFAKCBlTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0yMTAzMTQwODUzMDVaMCoGCSqGSIb3DQEJNDEdMBswDQYJYIZIAWUDBAIBBQChCgYIKoZIzj0EAwIwLwYJKoZIhvcNAQkEMSIEICPZfeIzu2S+cIEUuBE8hAj4r0p8sLuTmJAmjRkh3kihMAoGCCqGSM49BAMCBEcwRQIga52wabSNeoid67HRQcA6gYRXFbQxEOLc9+8dw13sQqcCIQDu8deNzrNjw0IZtSNKggxAuBah6vlU3jV7g/KP5NYU+AAAAAAAAA==",
                                          "header":{
                                              "publicKeyHash":"Bw2jd/MOcWGckejernjkTIq7mHTAQNWQKcq1gWcIXa7QM=",
                                              "ephemeralPublicKey":"MFkwEwYHKkejkfjcekr0DAQcDQgAEph3VTEk5p2MRTZp/VvPW6kj/A48iPL7B9kyEfUVlvI649kEch/+8XGsVtLaDe9oLjc9NY44JbuU1WKdcirujzw==",
                                              "transactionId":"8afa0035a55ca99004943nh55923hc99f799a61d3997cf8c1463fc6a36d2ad4ad78"
                                          },
                                          "version":"EC_v1"
                                      }))
var config = {
 method: 'post',
 url: 'https://api.moyasar.com/v1/payments',
 headers: {
   'Content-Type': 'application/json',
   'Authorization': 'Basic " + btoa("pk_live_nwC516XHiZn5TLSskHX2sWQtW8Hveuau6fCCQEXH" + ":")'
 },
 data : data
};

axios(config)
.then(function (response) {
 console.log(JSON.stringify(response.data));
})
.catch(function (error) {
 console.log(error);
});

<?php

 $curl = curl_init();

 curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.moyasar.com/v1/payments',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
  "amount":100,
  "description": "apple pay request example",
  "source":{
    "type":"applepay",
    "token": {"data":"4t0A+GFsVZ6BQhqr9KGnQazrW2G2V6j0X3qbx9MMCdr+s7MicdiURN472m1eQFhwPK58MFaiuufbA0AQUTb/cZaxktBpS3EhBFaSbmh/X+EuzIY4Vh++Vt5kXmoUY9VwDJw/yfFGvS29eIOHR6VKLhsNL1sm/u/qmo+tcvJAqtpQXQJStrWjUapnIz9U0ZeLoQSdtIvd0ihtVpq76spHFuom3yOoSVmFcX/X89vTTcdW0itRcve9pTOIsw+z+hGxgsmTaZF/ZgM6rPQgBfUZqDgsTMd/gWcBUIxtxUhA6/Dyzcm590w01kcKtwNzfepMuiElqvQ7Gu30vch3b6JtQhQs3Mr/BvPJOKRjpV+9fz6vBS55tmFVVTGmXKW5SWWfZiYy8tsxr0OEIdHMxf2cSE80=",
                      "signature":"MIAGCSqGSIb3DQEHAEFADCABgkqhkiG9w0BBwEAAKCAMIID4zCCA4igAwIBAgIITDBBSVGdVDYwCgYIKoZIzj0EAwIwejEuMCwGA1UEAwwlQXBwbGUgQXBwbGljYXRpb24gSW50ZWdyYXRpb24gQ0EgLSBHMzEmMCQGA1UECwwdQXBwbGUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxEzARBgNVBAoMCkFwcGxlIEluYy4xCzAJBgNVBAYTAlVTMB4XDTE5MDUxODAxMzI1N1oXDTI0MDUxNjAxMzI1N1owXzElMCMGA1UEAwwcZWNjLXNt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Rpb24gQ0EgLSBHMzEmMCQGA1UECwwdQXBwbGUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxEzARBgNVBAoMCkFwcGxlIEluYy4xCzAJBgNVBAYTAlVTAghMMEFJUZ1UNjANBglghkgBZQMEAgEFAKCBlTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0yMTAzMTQwODUzMDVaMCoGCSqGSIb3DQEJNDEdMBswDQYJYIZIAWUDBAIBBQChCgYIKoZIzj0EAwIwLwYJKoZIhvcNAQkEMSIEICPZfeIzu2S+cIEUuBE8hAj4r0p8sLuTmJAmjRkh3kihMAoGCCqGSM49BAMCBEcwRQIga52wabSNeoid67HRQcA6gYRXFbQxEOLc9+8dw13sQqcCIQDu8deNzrNjw0IZtSNKggxAuBah6vlU3jV7g/KP5NYU+AAAAAAAAA==",
                      "header":{
                          "publicKeyHash":"Bw2jd/MOcWGckejernjkTIq7mHTAQNWQKcq1gWcIXa7QM=",
                          "ephemeralPublicKey":"MFkwEwYHKkejkfjcekr0DAQcDQgAEph3VTEk5p2MRTZp/VvPW6kj/A48iPL7B9kyEfUVlvI649kEch/+8XGsVtLaDe9oLjc9NY44JbuU1WKdcirujzw==",
                          "transactionId":"8afa0035a55ca99004943nh55923hc99f799a61d3997cf8c1463fc6a36d2ad4ad78"
                      },
                      "version":"EC_v1"}
   },
 }',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    "Authorization: Basic " . base64_encode( "pk_live_nwC516XHiZn5TLSskHX2sWQtW8Hveuau6fCCQEXH:")
  ),
 ));

 $response = curl_exec($curl);

 curl_close($curl);
 echo $response;

 require "uri"
 require "net/http"

 url = URI("https://api.moyasar.com/v1/payments")

 https = Net::HTTP.new(url.host, url.port)
 https.use_ssl = true

 request = Net::HTTP::Post.new(url)
 request["Content-Type"] = "application/json"
 request.basic_auth("pk_live_nwC516XHiZn5TLSskHX2sWQtW8Hveuau6fCCQEXH:")
 request.body = '{
                  "amount":100,
                  "description": "apple pay request example",
                  "source":{
                    "type":"applepay",
                    "token": {"data":"4t0A+GFsVZ6BQhqr9KGnQazrW2G2V6j0X3qbx9MMCdr+s7MicdiURN472m1eQFhwPK58MFaiuufbA0AQUTb/cZaxktBpS3EhBFaSbmh/X+EuzIY4Vh++Vt5kXmoUY9VwDJw/yfFGvS29eIOHR6VKLhsNL1sm/u/qmo+tcvJAqtpQXQJStrWjUapnIz9U0ZeLoQSdtIvd0ihtVpq76spHFuom3yOoSVmFcX/X89vTTcdW0itRcve9pTOIsw+z+hGxgsmTaZF/ZgM6rPQgBfUZqDgsTMd/gWcBUIxtxUhA6/Dyzcm590w01kcKtwNzfepMuiElqvQ7Gu30vch3b6JtQhQs3Mr/BvPJOKRjpV+9fz6vBS55tmFVVTGmXKW5SWWfZiYy8tsxr0OEIdHMxf2cSE80=",
                      "signature":"MIAGCSqGSIb3DQEHAEFADCABgkqhkiG9w0BBwEAAKCAMIID4zCCA4igAwIBAgIITDBBSVGdVDYwCgYIKoZIzj0EAwIwejEuMCwGA1UEAwwlQXBwbGUgQXBwbGljYXRpb24gSW50ZWdyYXRpb24gQ0EgLSBHMzEmMCQGA1UECwwdQXBwbGUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxEzARBgNVBAoMCkFwcGxlIEluYy4xCzAJBgNVBAYTAlVTMB4XDTE5MDUxODAxMzI1N1oXDTI0MDUxNjAxMzI1N1owXzElMCMGA1UEAwwcZWNjLXNtcC1icm9rZXItc2lnbl9VQzQtUFJPRDEUMBIGA1UECwwLaU9TIFN5c3RlbXMxEzARBgNVBAoMCkFwcGxlIEluYy4xCzAJBgNVBAYTAlVTMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEwhV37evWx7Ihj2jdcJChIY3HsL1vLCg9hGCV2Ur0pUEbg0IO2BHzQH6DMx8cVMP36zIg1rrV1O/0komJPnwPE6OCAhEwggINMAwGA1UdEwEB/wQCMAAwHwYDVR0jBBgwFoAUI/J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KoZIzj0EAwIwLwYJKoZIhvcNAQkEMSIEICPZfeIzu2S+cIEUuBE8hAj4r0p8sLuTmJAmjRkh3kihMAoGCCqGSM49BAMCBEcwRQIga52wabSNeoid67HRQcA6gYRXFbQxEOLc9+8dw13sQqcCIQDu8deNzrNjw0IZtSNKggxAuBah6vlU3jV7g/KP5NYU+AAAAAAAAA==",
                      "header":{
                        "publicKeyHash":"Bw2jd/MOcWGckejernjkTIq7mHTAQNWQKcq1gWcIXa7QM=",
                        "ephemeralPublicKey":"MFkwEwYHKkejkfjcekr0DAQcDQgAEph3VTEk5p2MRTZp/VvPW6kj/A48iPL7B9kyEfUVlvI649kEch/+8XGsVtLaDe9oLjc9NY44JbuU1WKdcirujzw==",
                        "transactionId":"8afa0035a55ca99004943nh55923hc99f799a61d3997cf8c1463fc6a36d2ad4ad78"
                        },
                      "version":"EC_v1"}
                   },
                 }'
 response = https.request(request)
 puts response.read_body
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

var semaphore = DispatchSemaphore (value: 0)

let parameters = '{
                   "amount":100,
                   "description": "apple pay request example",
                   "source":{
                     "type":"applepay",
                     "token": {"data":"4t0A+GFsVZ6BQhqr9KGnQazrW2G2V6j0X3qbx9MMCdr+s7MicdiURN472m1eQFhwPK58MFaiuufbA0AQUTb/cZaxktBpS3EhBFaSbmh/X+EuzIY4Vh++Vt5kXmoUY9VwDJw/yfFGvS29eIOHR6VKLhsNL1sm/u/qmo+tcvJAqtpQXQJStrWjUapnIz9U0ZeLoQSdtIvd0ihtVpq76spHFuom3yOoSVmFcX/X89vTTcdW0itRcve9pTOIsw+z+hGxgsmTaZF/ZgM6rPQgBfUZqDgsTMd/gWcBUIxtxUhA6/Dyzcm590w01kcKtwNzfepMuiElqvQ7Gu30vch3b6JtQhQs3Mr/BvPJOKRjpV+9fz6vBS55tmFVVTGmXKW5SWWfZiYy8tsxr0OEIdHMxf2cSE80=",
                               "signature":"MIAGCSqGSIb3DQEHAEFADCABgkqhkiG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cm9vdGNhZzMuY3JsMA4GA1UdDwEB/wQEAwIBBjAQBgoqhkiG92NkBgIOBAIFADAKBggqhkjOPQQDAgNnADBkAjA6z3KDURaZsYb7NcNWymK/9Bft2Q91TaKOvvGcgV5Ct4n4mPebWZ+Y1UENj53pwv4CMDIt1UQhsKMFd2xd8zg7kGf9F3wsIW2WT8ZyaYISb1T4en0bmcubCYkhYQaZDwmSHQAAMYIBjDCCAYgCAQEwgYYwejEuMCwGA1UEAwwlQXBwbGUgQXBwbGljYXRpb24gSW50ZWdyYXRpb24gQ0EgLSBHMzEmMCQGA1UECwwdQXBwbGUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxEzARBgNVBAoMCkFwcGxlIEluYy4xCzAJBgNVBAYTAlVTAghMMEFJUZ1UNjANBglghkgBZQMEAgEFAKCBlTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0yMTAzMTQwODUzMDVaMCoGCSqGSIb3DQEJNDEdMBswDQYJYIZIAWUDBAIBBQChCgYIKoZIzj0EAwIwLwYJKoZIhvcNAQkEMSIEICPZfeIzu2S+cIEUuBE8hAj4r0p8sLuTmJAmjRkh3kihMAoGCCqGSM49BAMCBEcwRQIga52wabSNeoid67HRQcA6gYRXFbQxEOLc9+8dw13sQqcCIQDu8deNzrNjw0IZtSNKggxAuBah6vlU3jV7g/KP5NYU+AAAAAAAAA==",
                               "header":{
                                    "publicKeyHash":"Bw2jd/MOcWGckejernjkTIq7mHTAQNWQKcq1gWcIXa7QM=",
                                    "ephemeralPublicKey":"MFkwEwYHKkejkfjcekr0DAQcDQgAEph3VTEk5p2MRTZp/VvPW6kj/A48iPL7B9kyEfUVlvI649kEch/+8XGsVtLaDe9oLjc9NY44JbuU1WKdcirujzw==",
                                    "transactionId":"8afa0035a55ca99004943nh55923hc99f799a61d3997cf8c1463fc6a36d2ad4ad78"
                               },
                               "version":"EC_v1"}
                    },
                  }'
let postData = parameters.data(using: .utf8)
let username = "pk_live_nwC516XHiZn5TLSskHX2sWQtW8Hveuau6fCCQEXH"
let password = ""
let loginString = String(format: "%@:%@", username, password)
let loginData = loginString.data(using: String.Encoding.utf8)!
let base64LoginString = loginData.base64EncodedString()
var request = URLRequest(url: URL(string: "https://api.moyasar.com/v1/payments")!,timeoutInterval: Double.infinity)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("Basic \(base64LoginString)", forHTTPHeaderField: "Authorization")

request.httpMethod = "POST"
request.httpBody = postData

let task = URLSession.shared.dataTask(with: request) { data, response, error in
 guard let data = data else {
   print(String(describing: error))
   semaphore.signal()
   return
 }
 print(String(data: data, encoding: .utf8)!)
 semaphore.signal()
}

task.resume()
semaphore.wait()

Note: we are using a hardcoded token in token: { .... } to show you the part that needs to be send to Moyasar, which is event.payment.token.paymentData , but in practice you will need to assign that value to a variable and make sure to convert it to JSON string before sending it in the request payload.


Apple Pay on Mobile Apps (iOS)

Overview

For Apple Pay integration you need to get a Merchant ID and a Payment Processing Certificate from Apple developer account. And you have to use the PassKit library.

PassKit allows:

  • To add Apple Pay to the mobile application.
  • To manage cards in the Wallet App.

Development Steps

1- Create Apple Merchant ID

2- Create Payment Processing Certificate

3- Enable Apple Pay in Xcode

4- Develop Apple Pay on your iOS app

Note 1: Send the payment token to Moyasar as explained in this step.

Note 2: Decode the paymentData value from Base64 to json string before sending it to Moyasar.


Last Modified : Mar 2021