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

Implement googlepay button #173

Merged
merged 9 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ export default class DefaultLayoutsClass extends Vue {
},
{
title: 'POST /convertToken',
to: '/debug/payments/googlepay/convertToken',
to: '/debug/payments/digitalWallets/convertToken',
},
]

Expand Down
116 changes: 116 additions & 0 deletions lib/googlePay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import IsReadyToPayRequest = google.payments.api.IsReadyToPayRequest
import PaymentDataRequest = google.payments.api.PaymentDataRequest
import ButtonOptions = google.payments.api.ButtonOptions
import IsReadyToPayResponse = google.payments.api.IsReadyToPayResponse
import IsReadyToPayPaymentMethodSpecification = google.payments.api.IsReadyToPayPaymentMethodSpecification

const DEFAULT_CONFIG = {
apiVersion: 2,
apiVersionMinor: 0,
allowedPaymentMethods: <IsReadyToPayPaymentMethodSpecification>{
type: 'CARD',
parameters: {
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
allowedCardNetworks: ['MASTERCARD', 'VISA'],
},
},
merchantInfo: {
merchantId: '12345678901234567890',
merchantName: 'Example Merchant',
},
tokenizationSpecification: {
type: 'PAYMENT_GATEWAY',
parameters: {
gateway: 'checkoutltd',
gatewayMerchantId: 'YOUR_PUBLIC_KEY',
},
},
transactionInfo: {
currencyCode: 'USD',
countryCode: 'US',
totalPriceStatus: 'FINAL',
totalPrice: '12.00',
checkoutOption: 'COMPLETE_IMMEDIATE_PURCHASE',
},
}

function getIsReadyToPayRequest() {
const isReadyToPayRequest: IsReadyToPayRequest = {
apiVersion: DEFAULT_CONFIG.apiVersion,
apiVersionMinor: DEFAULT_CONFIG.apiVersionMinor,
allowedPaymentMethods: [DEFAULT_CONFIG.allowedPaymentMethods],
}
return isReadyToPayRequest
}

const paymentDataRequest: PaymentDataRequest = {
apiVersion: 2,
apiVersionMinor: 0,
merchantInfo: {
merchantId: '12345678901234567890',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we would want it to be real merchant id and name for stg/prod, will we store them in ssm in next PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will store the merchant values and Checkout details in SSM for next PR

Copy link
Contributor

@antiv0 antiv0 Mar 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// just for Eliza, just in case when doing next steps, secrets go to kubernetes db (which is likely etcd), not in aws ssm

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious on where/what the local secret is stored?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is public repo, in private repo deployment is defined

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wrong, it should live in K8S secrets for sample apple private

merchantName: 'Example Merchant',
},
allowedPaymentMethods: [
{
type: 'CARD',
parameters: {
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
allowedCardNetworks: ['MASTERCARD', 'VISA'],
},
tokenizationSpecification: {
type: 'PAYMENT_GATEWAY',
parameters: {
gateway: 'checkoutltd',
gatewayMerchantId: 'YOUR_PUBLIC_KEY',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay I think we can put it in SSM as well

},
},
},
],
transactionInfo: {
currencyCode: 'USD',
countryCode: 'US',
totalPriceStatus: 'FINAL',
totalPrice: '12.00',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, will we remove this hardcoded value in next PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will be removing or moving all hardcoded values in the next PR, just had them here for testing purposes for now

checkoutOption: 'COMPLETE_IMMEDIATE_PURCHASE',
},
}

interface PaymentToken {
protocolVersion: string
signature: string
intermediateSigningKey: Object
signedMessage: string
}

let paymentsClient: any = null

function getGooglePaymentsClient() {
if (paymentsClient === null) {
paymentsClient = new google.payments.api.PaymentsClient({
environment: 'TEST', // TODO: get real environment once implementation is finished
})
}
return paymentsClient
}

function onGooglePayLoaded(buttonOptions: ButtonOptions) {
paymentsClient = getGooglePaymentsClient()
paymentsClient
.isReadyToPay(getIsReadyToPayRequest())
.then(function (response: IsReadyToPayResponse) {
if (response.result) {
const button = paymentsClient.createButton(buttonOptions)
document.getElementById('google-pay-button')?.append(button)
Copy link
Contributor

@antiv0 antiv0 Mar 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: nowhere else in this codebase is DOM manipulated
somebody with good experience in our frontend stack could likely propose a way to do this that is in line with rest of codebase

like usage of Vue's v-if/v-on.. (i haven't dealt here with rendering of elements once promises resolve to know, but it seems to me somebody frontend should check it out)

}
})
.catch(function (err: any) {
console.error(err)
})
}

export {
onGooglePayLoaded,
getGooglePaymentsClient,
paymentDataRequest,
PaymentToken,
}
20 changes: 20 additions & 0 deletions lib/walletsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,30 @@ function getMasterWallet() {
return instance.get(url)
}

/**
* Convert digital wallets token
* @param {String} type
* @param {Object} tokenData
* @param {UUID} idempotencyKey
*/
function convertToken(type: string, tokenData: Object) {
const url = '/v1/tokens'
const payload = {
type,
tokenData,
idempotencyKey: '394dffd9-e992-4b86-b3f3-0a242a44db48',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not have this be randomly generated in this PR ?

}
const config = {
headers: { 'Access-Control-Allow-Origin': '*' },
}
return instance.post(url, payload, config)
}

export default {
getInstance,
getWallets,
getWalletById,
createWallet,
getMasterWallet,
convertToken,
}
7 changes: 7 additions & 0 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export default {
},
],
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
script: [
{
src: 'https://pay.google.com/gp/p/js/pay.js',
async: true,
defer: true,
},
],
},
/*
** Customize the progress-bar color
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"@nuxtjs/dotenv": "1.4.1",
"@nuxtjs/vuetify": "1.12.2",
"@types/card-validator": "7.0.1",
"@types/googlepay": "^0.6.4",
"@types/vue-the-mask": "0.11.1",
"axios": "0.24.0",
"card-validator": "8.1.1",
Expand All @@ -50,6 +49,7 @@
"@nuxtjs/eslint-config-typescript": "8.0.0",
"@nuxtjs/eslint-module": "3.0.2",
"@types/applepayjs": "3.0.3",
"@types/googlepay": "0.6.4",
"@types/lodash": "4.14.177",
"@types/openpgp": "4.4.18",
"@types/uuid": "8.3.3",
Expand Down
7 changes: 4 additions & 3 deletions pages/debug/payments/create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
<v-text-field v-if="cvvRequired" v-model="formData.cvv" label="CVV" />

<v-text-field
v-if="formData.sourceType != 'token'"
v-model="formData.verificationSuccessUrl"
label="VerificationSuccessUrl"
/>

<v-text-field
v-if="formData.sourceType != 'token'"
v-model="formData.verificationFailureUrl"
label="VerificationFailureUrl"
/>
Expand Down Expand Up @@ -125,7 +127,7 @@ export default class CreatePaymentClass extends Vue {
}

verificationMethods = ['none', 'cvv', 'three_d_secure']
sourceType = ['card', 'ach']
sourceType = ['card', 'ach', 'token']
required = [(v: string) => !!v || 'Field is required']
error = {}
loading = false
Expand Down Expand Up @@ -154,8 +156,7 @@ export default class CreatePaymentClass extends Vue {
onSourceTypeChanged(val: string) {
if (val === 'card') {
this.formData.verification = 'cvv'
}
if (val === 'ach') {
} else {
this.formData.verification = 'none'
}
}
Expand Down
Loading