Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support to google-pay #733

Merged
merged 3 commits into from
Jul 8, 2022
Merged

Adding support to google-pay #733

merged 3 commits into from
Jul 8, 2022

Conversation

cyberxander90
Copy link
Contributor

@cyberxander90 cyberxander90 commented Jun 16, 2022

Description

Adding support to Google Pay in Recurly.

Google Pay integrations are based on the TokenizationSpecification which could be on 2 ways:

NOTE: This implementation is only to support Gateway integration.

The implementation is based on 2 components

  • the pay-with-google used to abstract the Google Pay functionality
  • the google-pay which internally use the pay-with-google and interact with recurly to get the merchant info and to create the token.

How to use it

In your html define where do you want to show the Google-Pay button

<div id="google-pay"></div>

In your script initialize the recurly.GooglePay

var googlePay = recurly.GooglePay({
  // required by google pay
  currency: 'USD',
  country: 'US',
  total: '10',
  googleMerchantId: 'GOOGLE_MERCHANT_ID',

  // optional
  environment: 'TEST', // environment is automatically deduced from your site mode, but you can override it with this options
  googleBusinessName: 'Google Bussiness Name',
  buttonOptions: {},  // see https://developers.google.com/pay/api/web/reference/request-objects#ButtonOptions
  requireBillingAddress: true,  // request the user billing address, not need it if provided the form option with the billing_address fields
  gatewayCode: 'GATEWAY_123',  // specify which gateway in Recurly must handle your payment
  form: document.querySelector('#billing-address-form'), // a form with the billing address, not need it if the billing address is requested to google
});

// the user/browser is available to Pay with Google
googlePay.on('ready', googlePayButton => {
    // add the button to the DOM
    $('#google-pay').appendChild(googlePayButton);
});

// recurly token generated
googlePay.on('token', token => {
    console.log(token);
});

// an error ocurred
googlePay.on('error', err => {
    console.error(err);
    
    // check what the error type is and take action
    console.log(err.code)
    console.log(err.message)
});

Specs

  • Pay with Google

    • ✔ loads the Google Pay script https://pay.google.com/gp/p/js/pay.js
    • when the script was already loaded and settle to window.google.payments.api.PaymentsClient
      • ✔ do not re-load the script
    • when failed loading the Google Pay script
      • ✔ rejects with a google-pay-init-error
    • when success loading the Google Pay script
      • ✔ initializes the Google PaymentClient with the environment provided
      • ✔ checks the Google Pay availability with the Google Pay Configuration provided
      • when fails checking the Google Pay availability
        • ✔ rejects with a google-pay-init-error
      • when there are no availability to pay with Google
        • ✔ rejects with a google-pay-not-available error
      • when there are availability to pay with Google
        • ✔ resolves the Google Pay button and a paymentData Emitter to get the user Payment Data
        • ✔ creates the Google Pay button with the button options provided
        • ✔ do not request the user Payment Data until the Google Pay button is clicked
        • when the Google Pay button is clicked
          • ✔ requests the user Payment Data with the PaymentDataRequest provided
          • when fails requesting the user Payment Data
            • ✔ the paymentData Emitter emits a google-pay-payment-failure error
          • when success requesting the user Payment Data
            • ✔ the paymentData Emitter emits the user Payment Data response
          • when the Google Pay button is clicked twice
            • ✔ the paymentData Emitter emits the user Payment Data response twice
  • Google Pay

    • ✔ requests to Recurly the merchant Google Pay info with the initial options provided
    • when missing a required option
      • :googleMerchantId
        • ✔ emits a google-pay-config-missing error
        • ✔ do not initiate the pay-with-google nor requests to Recurly the merchant Google Pay info
        • ✔ do not emit any token nor the on ready event
      • :total
        • ✔ emits a google-pay-config-missing error
        • ✔ do not initiate the pay-with-google nor requests to Recurly the merchant Google Pay info
        • ✔ do not emit any token nor the on ready event
      • :country
        • ✔ emits a google-pay-config-missing error
        • ✔ do not initiate the pay-with-google nor requests to Recurly the merchant Google Pay info
        • ✔ do not emit any token nor the on ready event
      • :currency
        • ✔ emits a google-pay-config-missing error
        • ✔ do not initiate the pay-with-google nor requests to Recurly the merchant Google Pay info
        • ✔ do not emit any token nor the on ready event
    • when fails requesting to Recurly the merchant Google Pay info
      • ✔ emits an api-error
      • ✔ do not initiate the pay-with-google
      • ✔ do not emit any token nor the on ready event
    • when the requested merchant Google Pay info returns an empty list of payment methods
      • ✔ emits a google-pay-not-configured error
      • ✔ do not initiate the pay-with-google
      • ✔ do not emit any token nor the on ready event
    • when the requested merchant Google Pay info returns a valid non-empty list of payment methods
      • ✔ initiates the pay-with-google with the expected Google Pay Configuration
      • when the site mode is production but an environment option is provided
        • ✔ initiates the pay-with-google in the specified environment
      • when the site mode is production and no environment option is provided
        • ✔ initiates the pay-with-google in PRODUCTION mode
      • when the site mode is any other than production but an environment option is provided
        • ✔ initiates the pay-with-google in the specified environment
      • when the site mode is any other than production and no environment option is provided
        • ✔ initiates the pay-with-google in TEST mode
      • when the billing address is not required
        • ✔ initiates the pay-with-google without the billing address requirement
      • when cannot proceed with the pay-with-google
        • ✔ emits the same error the pay-with-google throws
        • ✔ do not emit any token nor the on ready event
      • when the pay-with-google success
        • ✔ emits the ready event with the google-pay button
        • when the google-pay button is clicked
          • ✔ requests the user Payment Data
          • when fails retrieving the user Payment Data
            • ✔ emits the same error that the retrieving process throws
            • ✔ do not request any token to Recurly
          • when success retrieving the user Payment Data
            • ✔ request to Recurly to create the token with the billing address from the user Payment Data
            • when the user provide a with custom billing address
              • ✔ request to Recurly to create the token with the billing address from the
            • when Recurly fails creating the token
              • ✔ emits an api-error
              • ✔ do not emit any token
            • when Recurly success creating the token
              • ✔ emits the token

@cyberxander90 cyberxander90 self-assigned this Jun 16, 2022
@cyberxander90 cyberxander90 force-pushed the google-pay branch 2 times, most recently from baf5723 to bd36def Compare June 16, 2022 18:49
@cyberxander90 cyberxander90 marked this pull request as draft June 16, 2022 19:07
@cyberxander90 cyberxander90 force-pushed the google-pay branch 2 times, most recently from f3d4242 to 938f088 Compare June 16, 2022 21:45
@coveralls
Copy link

coveralls commented Jun 16, 2022

Coverage Status

Coverage increased (+0.001%) to 92.556% when pulling 96a0033 on google-pay into f6725ca on master.

@cyberxander90 cyberxander90 marked this pull request as ready for review June 17, 2022 14:28
@cyberxander90 cyberxander90 force-pushed the google-pay branch 3 times, most recently from 96a0033 to 422f687 Compare June 22, 2022 12:54
@cyberxander90 cyberxander90 force-pushed the google-pay branch 2 times, most recently from e782c38 to d3368f7 Compare June 23, 2022 13:23
@epagerecurly epagerecurly merged commit 047d61f into master Jul 8, 2022
@epagerecurly epagerecurly deleted the google-pay branch July 8, 2022 14:58
recurly-integrations pushed a commit that referenced this pull request Jul 11, 2022
[Full Changelog](v4.21.1...v4.22.0)

**Merged Pull Requests**

- Add more BIN ranges for UnionPay [#735](#735) ([douglaslise](https://github.com/douglaslise))
- Adding support to google-pay [#733](#733) ([cyberxander90](https://github.com/cyberxander90))

##### Minified MD5 Checksum
```
31b1262e3c24b7d976b8ac059272fc70 ./build/recurly.min.js
```
##### [SRI Hash](https://www.srihash.org/)
```
kBvjBMTBLtCfRYmRi0vXxHc3caUNArpOcsZ7XJinK8NCan7tqdmO30JHlASFVdWa
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants