Skip to content

Instantly share code, notes, and snippets.

@wehub
wehub / apple_pay_sample_code.js
Last active April 16, 2018 16:43
Sample code for Apple Pay
$(function() {
// Point WePay to stage
WePay.set_endpoint("stage");
// Use your WePay client and account IDs here.
var clientId = 12345;
var accountId = 123456789;
// This is your Apple-registered merchant identifier
var merchantId = "example.com.wepay";
//LineItem:
var lineItem = {
type: "final",
label: "Subtotal",
amount: "1234.56"
};
//PaymentContact:
var contact = {
emailAddress: "test@email.com",
$(".checkout.index").ready(function() {
// Point WePay to stage
WePay.set_endpoint("stage");
// Use your WePay client and account IDs here.
var clientId = 12345;
var accountId = 1234567890;
// Merchant ID is reserved for Apple Pay. For Payment Request API, use `undefined`
var merchantId = undefined;
//Amount:
var amount = {
currency: "USD",
value: "4.50"
};
//LineItem < Item:
var lineItem = {
label: “Subtotal”,
amount: amount
// WePay PHP SDK - http://git.io/mY7iQQ
require 'wepay.php';
// oauth2 parameters
<span class="variable">$code</span> = $_GET['code']; // the code parameter from step 2
<span class="variable">$redirect_uri</span> = "http://www.example.com/oauth2_redirect_uri"; // this is the redirect_uri you used in step 1
// application settings
<span class="variable">$client_id</span> = 123456789;
<span class="variable">$client_secret</span> = "1a3b5c7d9";
curl https://stage.wepayapi.com/v2/oauth2/token \
-d "client_id=123456789" \
-d "client_secret=1a3b5c7d9" \
-d "code=52sdga231sddd213jj9a" \
-d "redirect_uri=http://www.example.com/oauth2_redirect_uri"
# WePay Ruby SDK - http://git.io/a_c2uQ
require 'wepay'
# application settings
client_id = '123456789'
client_secret = '1a3b5c7d9'
use_stage = true
wepay = WePay::Client.new(client_id, client_secret, use_stage)
# WePay Python SDK - http://git.io/v7Y1jA
from wepay import WePay
# oauth2 parameters
code = '52sdga231sddd213jj9a'; # the code parameter from step 2
redirect_uri = "http://www.example.com/oauth2_redirect_uri"; # this is the redirect_uri you used in step 1
# application settings
client_id = 123456789
client_secret = '1a3b5c7d9'
<?php
// WePay PHP SDK - http://git.io/mY7iQQ
require 'wepay.php';
// application settings
$client_id = 123456789;
$client_secret = "1a3b5c7d9";
$access_token = "STAGE_8a19aff55b85a436dad5cd1386db1999437facb5914b494f4da5f206a56a5d20";
// change to useProduction for live environments
curl https://stage.wepayapi.com/v2/preapproval/create \
-H "Authorization: Bearer STAGE_8a19aff55b85a436dad5cd1386db1999437facb5914b494f4da5f206a56a5d20" \
-d "account_id=123456789" \
-d "period=once" \
-d "amount=19.99" \
-d "mode=regular" \
-d "short_description=A subscription to our magazine." \
-d "redirect_uri=http://example.com/success/"