getPaymentToken
Starting with v24.3, this is deprecated.
Initiates a payment flow using a configured payment processor.
Syntax
function getPaymentToken(configAlias: string, referenceId: string, info: any, billing: any): any
| Parameter | Description |
|---|---|
configAlias
|
The alias for a configured payment processor service. For information on how to configure a link to a payment processor service, see the Innovation Core User Guide. |
referenceId
|
Payment reference ID. |
info
|
JSON object containing invoicing information. The object has the following structure: Copy |
billing
|
JSON object containing billing information. The object has the following structure: Copy |
Return Value
Returns a JSON object containing parameters needed to redirect the user to the payment processor's payment page:
{
encodedToken : string;
envelope : string;
callUrl : string;
}
This allows you to create client-side forms that will redirect the user to the payment processor's payment page:
<form id="NetopiaPostForm" name="RedirectAndPOST" action="<callUrl>" method="POST">
<input type="hidden" name="data" value="<encodedToken>" />
<input type="hidden" name="env_key" value="<envelope>" />
<button type="submit">Go to Pay!</button>
</form>
Once the payment is finalized, a callback from the payment processor will be directed to the PaymentProcessorCallbackController endpoint, which will populate the ReferenceId and LogData attributes of the PaymentProcessorLog entity with the transaction's details.
Examples
In this example, we initiate a payment process on a checkout user journey. The user journey is based on a form driven flow wizard.
Client side setup
On the client side, in the flow step that precedes the payment and, in the After Section Save code section:
- We send the transaction data (order number, amount, currency, details, address, email, telephone number, user first name, and user last name) to the paymentProcessorEp endpoint using the ebs.callActionByNameAsync method.
- We save the payment parameters returned from the endpoint in formScope variables, so that we can use them in the subsequent flow step where the user can proceed with the payment.
ebs.callActionByNameAsync('paymentProcessorEp', {
referenceId: formData.model.orderNumber,
amount_in: formData.model.amount,
currency_in: formData.model.currency,
details_in: formData.model.details,
address_in: formData.model.address,
email_in: formData.model.email,
firstName_in: formData.model.firstName,
lastName_in: formData.model.lastName,
phone_in: formData.model.phone
}).then(function (response) {
formScope.callURL = response.UIResult.Data.callURL;
formScope.encryptedToken = response.UIResult.Data.encryptedToken;
formScope.envelope = response.UIResult.Data.envelope
})
Server side setup
On the server side, the script behind the paymentProcessorEp endpoint uses the transaction data received from the client process (order number, amount, currency, details, address, email, telephone number, user first name, and user last name) to obtain the payment parameters from the mobilPay payment processor. Then, it passes the payment parameters to the client process using the ftos.context.response.setData function:
let info = {
amount: ftos.context.data.amount_in,
currency: ftos.context.data.currency_in,
details: ftos.context.data.details_in
};
let billing = {
address: ftos.context.data.address_in,
email: ftos.context.data.email_in,
firstName: ftos.context.data.firstName_in,
lastName: ftos.context.data.lastName_in,
phone: ftos.context.data.phone_in
};
let paymentParameters = getPaymentToken('mobilPay', ftos.context.data.referenceId, info, billing);
ftos.context.response.setData({
'callUrl': paymentParameters.callUrl,
'encodedToken': paymentParameters.encodedToken,
'envelope': paymentParameters.envelope
})