An important part of the SDK transaction.
This function is the core of the SDK Giving Form. All relevant form data converges on this function and results in a completed transaction.
Method
Accepts a ReCaptcha Token as an argument. Relies on local object theData, sourced from HTML form and converted to convenient objects for passing to functions.
function recaptchaCallback(recaptchaToken) {
try {
//begin process
idonateClient.tokenizeSpreedlyCreditCard({
contact: theData.billingContact,
address: theData.billingAddress,
card:{
cardNumber: $('#cardData-cardNumber').val(),
expirationMonth: $('#cardData-expirationMonth').val(),
expirationYear: $('#cardData-ExpirationYear').val()
}
}).then((tokenResult) => {
return idonateClient.createPaymentMethod({
//RecaptchaSecuredRequest type
recaptchaType: config.recaptchaType,
recaptchaToken: recaptchaToken,
//CreatePaymentMethodRequest type
paymentGatewayId: config.paymentGatewayId,
paymentMethodType: 'credit_card',
paymentMethodToken: tokenResult,
contact: theData.billingContact,
address: theData.billingAddress
})
}).then((paymentMethodResult) => {
return idonateClient.createTransaction({
//RecaptchaSecuredRequest type
recaptchaType: config.recaptchaType,
recaptchaToken: recaptchaToken,
//CreateTransactionRequest type
paymentGatewayId: config.paymentGatewayId,
paymentMethodId: paymentMethodResult.paymentMethodId,
recurringFrequency: theData.recurringFrequency,
paymentAmount: theData.paymentAmount,
donorPaidFeeAmount: theData.donorPaidFeeAmount, //optional field, null if not used
designations: theData.designations,
currency: theData.currency,
billingContact: theData.billingContact,
billingAddress: theData.billingAddress,
customerMeta: { //this must be an object
yourFieldName: "yourValueName"
},
recaptchaToken: recaptchaToken,
corporateMatchingId: -1, //required field, omitted on form in this case
})
}).then((createTransactionResult) => {
theData.truncatedCardData = "****" + $('#cardData-cardNumber').val().slice(12,16); //for use in receipt page
//render receipt page
renderReceiptElements(createTransactionResult);
})
} catch (e) {
handleTheError(e);
}
}