Introduction
Agreement
Authentication
Batch
Browser Payment
Gateway
Hosted Checkout
Payment Plan
Session
Standalone Risk Assessment
Tokenization
Transaction
Wallet
RESOURCES
Changelog
Session
updateSessionFromForm()
updateSessionFromForm()
Request to store the input provided by the payer in the hosted field(s) into the session. You must provide the payment type for which the fields must be stored. For a gift card you must also provide the local card brand. The result of the request is returned in the formSessionUpdate callback. Note that this callback is defined in the configure() function.
Usage
PaymentSession.updateSessionFromForm( )
Example
PaymentSession.configure({ callbacks: { formSessionUpdate: function(response) { // HANDLE RESPONSE FOR UPDATE SESSION if (response.status) { if ("ok" == response.status) { console.log("Session updated with data: " + response.session.id); //check if the security code was provided by the user if (response.sourceOfFunds.provided.card.securityCode) { console.log("Security code was provided."); } //check if the user entered a MasterCard credit card if (response.sourceOfFunds.provided.card.scheme == 'MASTERCARD') { console.log("The user entered a MasterCard credit card.") } } else if ("fields_in_error" == response.status) { console.log("Session update failed with field errors."); if (response.errors.cardNumber) { console.log("Card number invalid or missing."); } if (response.errors.expiryYear) { console.log("Expiry year invalid or missing."); } if (response.errors.expiryMonth) { console.log("Expiry month invalid or missing."); } if (response.errors.securityCode) { console.log("Security code invalid."); } } else if ("payment_type_required" == response.status) { console.log("Payment type is required. Valid values are 'card', 'ach' or 'giftCard'."); } else if ("giftCard_type_required" == response.status) { console.log("Gift card payment type requires an expected local brand parameter."); } else if ("request_timeout" == response.status) { console.log("Session update failed with request timeout: " + response.errors.message); } else if ("system_error" == response.status) { console.log("Session update failed with system error: " + response.errors.message); } } else { console.log("Session update failed: " + response); } } } }); // Response handling is done in the callbacks.formSessionUpdate callback function is a part of configure() function. PaymentSession.updateSessionFromForm('card');
JSON Example for Session Update Response
// status can be one of the following: ok, fields_in_error, system_error, request_timeout // An error response (fields_in_error) { "status": "fields_in_error", "session": { "id": "SESSION000218450948092491657986" }, "errors": { "cardNumber": "invalid", "securityCode": "invalid" }, version: "36" } // An error response (system_error) { "status": "system_error", "session": { "id": "SESSION000218450948092491657986" }, "errors": { "message": "System error message." }, "version": "36" } // An error response (request_timeout) { "status" : "request_timeout", "session": { "id": "SESSION000218450948092491657986" }, "errors": { "message": "Request timeout error message." }, "version": "36" } // An ok response { "status":"ok", "merchant": "TESTMERCHANT", "session": { "id": "SESSION000218450948092491657986" "updateStatus":"SUCCESS", "version":"e3f144ce02" }, "sourceOfFunds": { "provided": { "card": { "brand": "MASTERCARD", "expiry": { "month": "1", "year": "39" }, "fundingMethod": "DEBIT", "nameOnCard": "John Smith", "number": "512345xxxxxx8769", "scheme": "MASTERCARD" } }, "type": "CARD" }, "version": "36" }
Arguments
paymentType
String
The payment type to update in the session. Valid values are:
card
ach
giftCard
directDebitCanada
localBrand
String
The local brand if the paymentType is 'giftCard'.
scope
String
The optional named instance of a card payment data set within a session. See Multiple Hosted Sessions for more information.
Return Value
None