Skip to content

Instantly share code, notes, and snippets.

@VizualAbstract
Created October 9, 2018 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VizualAbstract/30c9b20e86e5dffb57373867407a2093 to your computer and use it in GitHub Desktop.
Save VizualAbstract/30c9b20e86e5dffb57373867407a2093 to your computer and use it in GitHub Desktop.
# For Apple Pay implementation (frontend)

For Apple Pay implementation (frontend)

by Corey

Payment Request Button

  • Upgrade Stripe JS api from v2 to v3
    • https://js.stripe.com/v3/
  • Add Stripe Element
    • <div id="payment-request-button">
  • Use Publishable Stripe API key
    • Stripe('pk_test_Ar4P8c2SvHTUYfsAF9aZuxTR');
    • Do we use Stripe Connect?
      • { stripeAccount: 'CONNECTED_STRIPE_ACCOUNT_ID' }
      • Register domain
  • Create PaymentRequest instance
    • stripe.paymentRequest()
    • country
    • currency
    • total
      • label
      • ammount
    • Any additional options (name, email, phone used for Apple Pay to assist in preventing fraudulent payments)
      • requestPayerName: true,
      • requestPayerEmail: true,
  • Create and "mount"/add button element
    • If failed, show the standard form and hide the button
  • Add a listener for the token
    • When token is generated, post charges
      • JSON
  • Determine if we need to collect shipping information
    • Do we already collect shipping information for Stripe?
    • requestShipping: true
    • Useful for updating amount if it changes
      • label: "Free shipping",
        detail: "Arrives in 5 to 7 days",
        amount: 0 }
        
      • If shipping can be altered on the same page?
      • If so, listen for 'shippingaddresschange' and update
      • Send request to re-calculate shipping charges as necessary
    • Let's use the default button
      • It can be styled
      • We can use our own in the future if necessary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment