-
Notifications
You must be signed in to change notification settings - Fork 7
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
Changes from all commits
04cbeca
767adbb
a341b83
9d813f3
d13a9c4
ccb3262
5c70672
f1e0d00
6747d54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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', | ||
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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, will we remove this hardcoded value in next PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: nowhere else in this codebase is DOM manipulated 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, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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