Developer Center

Tokenized Method

It is a type in which a customer enters their credit card information without leaving WISECP, optionally chooses the card saving feature, and transmits this information to the payment service provider without being stored locally, and in return, the payment is collected with the tokens received. Payment transactions are carried out with the token received from the payment provider.

The "Tokenized" method has the same steps as the "Merchant" method. What you need to do is to activate the "Card Storage" feature and introduce the "token" information obtained from the payment service provider to the WISECP.

Enabling Card Storage

As mentioned before, if you define the "card-storage-supported" index as a "true" value in the "config.php" file, you will enable the card storage feature for the module.

Collecting Payment

The card information defined by the customer is transmitted to the "capture" function. If a "stored" card is selected, the "card_storage" index is "full" in the parameter passed to the function.

Variables

All the variables mentioned below are passed to the "capture" function.

Name Type Explanation
checkout_id integer Unique ID number for payment (eg: 1234567)
amount float Amount to be paid information
currency integer Currency code (eg: USD, EUR, etc…)
installment integer How many installments are requested
holder_name string Name on the card
type string Card type (Ex. VISA, MASTERCARD, etc.)
num integer 16 digit card number
expiry_m integer Month info of expiry date of card (eg: 07)
expiry_y integer Year info of expiry date of card (eg: 27)
cvc integer Security code on the back of the card
clientInfo object It is an "object" variable with customer information.
card_storage array Stored card info
card_storage -> id integer Stored card ID number
card_storage -> user_id integer Customer's ID number
card_storage -> as_default integer "1" if card is default, "0" if not
card_storage -> card_country string Country info of the card (eg: US, UK, DE, etc…)
card_storage -> card_type string Type of card (can take the value "debit" and "credit").
card_storage -> card_schema string The scheme of the card (eg: "MASTERCARD", "VISA", etc.)
card_storage -> card_brand string The brand of the card (e.g. "American Express" etc.)
card_storage -> bank_name string The name of the bank to which the card belongs
card_storage -> ln4 string Last 4 numbers of card number
card_storage -> cvc string Security code on the back of the card (kept encrypted in the database)
card_storage -> name string Name on the card
card_storage -> expiry_month string Month info of expiry date of card (eg: 07)
card_storage -> expiry_year string Year info of expiry date of card (eg: 27)
card_storage -> token string Token info obtained from the payment service provider (kept encrypted in the database)

Sample

public function capture($params=[])
{
    $api_key            = $this->config["settings"]["example1"] ?? 'N/A';
    $secret_key         = $this->config["settings"]["example2"] ?? 'N/A';
    $storage_token      = '';

    if($params['card_storage'])
        $storage_token = $params['card_storage']['token'];


    if($storage_token)
        $card = [];
    else
        $card = [
            'card_number'        => $params['num'],
            'card_holder_name'   => $params['holder_name'],
            'card_expiry'        => $params['expiry_m']."-".$params['expiry_y'],
            'card_cvc'           => $params['cvc'],
        ];

    // Does the customer want to keep the card?
    if($this->checkSaveCard()) $card['card_storage'] = 'enable';


    $fields             = [
        'client' => [
            'first_name'    => $params["clientInfo"]->name,
            'last_name'     => $params["clientInfo"]->surname,
            'email'         => $params["clientInfo"]->email,
            'address'       => [
                'country'       => $params["clientInfo"]->address->country_code,
                'city'          => $params["clientInfo"]->address->city,
                'state'         => $params["clientInfo"]->address->counti,
                'postcode'      => $params["clientInfo"]->address->zipcode,
                'detail'        => $params["clientInfo"]->address->address,
            ],
        ],
        'card'                  => $card,
        'storage_token'         => $storage_token,
        'amount'                => $params['amount'],
        'currency'              => $this->currency($params['currency']),
        'custom_id'             => $params["checkout_id"],
    ];


    // Here we are making an API call.
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "api.sample.com/checkout/capture");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
        'APIKEY: '.$api_key,
        'SECRET: '.$secret_key,
        'Content-Type: application/json',
    ));
    curl_setopt($curl,CURLOPT_POST,1);
    curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($fields));
    $result = curl_exec($curl);
    if(curl_errno($curl))
    {
        return [
            'status' => 'error',
            'message' => curl_error($curl)
        ];
    }
    $result             = json_decode($result,true);

    if($result && $result['status'] == 'success')
        return [
            'status' => 'successful',
            'message' => ['Merchant Transaction ID' => $result['transaction_id']],
            'card_storage_token' => $result["storage_token"] ?? '',
        ];
    else
        return [
            'status'            => 'error',
            'message'           => $result['error_message'] ?? '!API ERROR!',
        ];

}

Deleting a Stored Card

If your payment service provider supports card deletion, you can use the function given below.

public function remove_stored_card($params=[])
{
    $api_key        = $this->config["settings"]["example1"] ?? 'N/A';
    $secret_key     = $this->config["settings"]["example2"] ?? 'N/A';
    $token          = $params['token'];

    // Here we are making an API call.
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "api.sample.com/card-storage/remove/".$token);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
        'APIKEY: '.$api_key,
        'SECRET: '.$secret_key,
        'Content-Type: application/json',
    ));
    $result = curl_exec($curl);
    if(curl_errno($curl))
    {
        $result      = false;
        $this->error = curl_error($curl);
    }
    $result             = json_decode($result,true);

    if($result && $result['status'] == 'OK') $result = true;
    else
    {
        $this->error = $result['message'] ?? 'something went wrong';
        $result = false;
    }

    return $result;
}
Merchant Method Subscription Method

Do you have any questions?

Feel free to contact us
Contact Us
Copyright © 2024. All Rights Reserved.
Join Our Discord Channel
Top

New Year's Special Discount

"Startup Lifetime" and "Professional Lifetime" licenses are 30% off!

Coupon Code:
HAPPYYEARS30 Copied!
Discount Rate 30%
Expiration Date December 31, 2024