Last active
April 24, 2025 08:03
-
-
Save konami99/cdce879a7413aa39f57afd835922c61d to your computer and use it in GitHub Desktop.
greenpay-google pay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tokenizationSpecification = { | |
type: 'PAYMENT_GATEWAY', | |
parameters: { | |
'gateway': 'fatzebra', | |
'gatewayMerchantId': "#{campaign.greenpay_googlepay_mid}" | |
} | |
}; | |
const allowedPaymentMethods = [{ | |
type: "CARD", | |
tokenizationSpecification: tokenizationSpecification, | |
parameters: { | |
allowedAuthMethods: ["PAN_ONLY", "CRYPTOGRAM_3DS"], | |
allowedCardNetworks: ["VISA", "MASTERCARD"] | |
} | |
}]; | |
const paymentDataRequest = { | |
apiVersion: 2, | |
apiVersionMinor: 0, | |
allowedPaymentMethods: allowedPaymentMethods, | |
transactionInfo: { | |
totalPriceStatus: "FINAL", | |
totalPrice: $("#donation_donation_total").val(), | |
currencyCode: "#{campaign.currency}" | |
}, | |
merchantInfo: { | |
merchantId: "#{campaign.greenpay_googlepay_mid}", | |
merchantName: "#{campaign.greenpay_merchant_username}" | |
} | |
}; | |
paymentsClient.loadPaymentData(paymentDataRequest) | |
.then(paymentData => { | |
console.log("Payment Success:", paymentData); | |
token = paymentData.paymentMethodData.tokenizationData.token; | |
const form = document.getElementById('new_donation'); | |
var donation_reference = document.createElement('input'); | |
donation_reference.setAttribute('type', 'text'); | |
donation_reference.setAttribute('name', 'donation[reference]'); | |
donation_reference.setAttribute('value', "#{reference}"); | |
donation_reference.setAttribute('class', 'hidden'); | |
form.append(donation_reference); | |
var greenpay_token = document.createElement('input'); | |
greenpay_token.setAttribute('type', 'text'); | |
greenpay_token.setAttribute('name', 'donation[greenpay_google_pay_nonce]'); | |
greenpay_token.setAttribute('value', token); | |
greenpay_token.setAttribute('class', 'hidden'); | |
form.append(greenpay_token); | |
form.submit(); | |
}) | |
.catch(error => { | |
console.error("Payment Failed:", error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment