updateSessionFromForm()

Sends a request to store the input from the hosted field(s) for the specified payment type, into the session. The supported payment types are 'card', 'ach', 'giftCard'. If paymentType === 'giftCard' then you must provide the local card brand as an additional parameter. The status of the request is returned in the formSessionUpdate callback function defined in the PaymentSession.configure( ) function.

Usage

PaymentSession.updateSessionFromForm(paymentType)

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
    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"
}

Return Value

None

Copyright © 2023 MasterCard