Developer Center

Merchant Method

It is a payment type in which a customer enters their credit card information without leaving WISECP. Processes are processed in the background.  Your customer may leave your site for 3D security verification only or see a popup for it. 

Follow the steps below to create a module according to the "Merchant" method.

Define a function called "capture" in the class in the module. The purpose of using this function is to transfer the credit card information obtained from the customer to the "capture" function. It is usually used to confirm the payment based on the response by sending an "HTTP/cURL" request to the payment service provider.

If your payment service provider supports "3D Secure", see the "3D Secure" document.

If your payment service provider supports the refund feature, see the "Refunds" document.

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 (eg: VISA, MASTERCARD etc.)
num integer 16 digit card number
expiry_m integer Month info on the expiration date of the card. (eg: 07)
expiry_y integer Year info on the expiration date of the card. (eg: 29)
cvc integer Security code on the back of card
clientInfo object It is an "object" variable with customer information.
clientInfo -> id integer ID Number
clientInfo -> name string Name
clientInfo -> surname string Last name
clientInfo -> full_name string Full name
clientInfo -> email string E-mail address
clientInfo -> gsm_cc integer GSM phone country code (eg: 1,44,90 etc.)
clientInfo -> gsm integer GSM phone number (without country code)
clientInfo -> phone İnteger GSM phone number (including country code)
clientInfo -> lang string Language used (eg:  en,fr,de, etc.)
clientInfo -> kind string Account type (eg: individual, corporate)
clientInfo -> company_name String Company name
clientInfo -> company_tax_number String Company tax number
clientInfo -> company_tax_office String Company tax office
clientInfo -> address > country_code string Country code of the selected address (eg: US,UK,DE etc.)
clientInfo -> address > country_name String Country name of the selected address
clientInfo -> address > city String City name of the selected address
clientInfo -> address > counti String County name of the selected address
clientInfo -> address > zipcode String Zipcode of the selected address
clientInfo -> address > address String Details of the selected address

System Variables

 $this->config["settings"]["...your_field..."] # Custom configuration field
 $this->name                   # Module Name
 $this->lang["invoice-name"]   # Module Display Name
 $this->url                    # Module Directory URL Address
 $this->dir                    # Module Directory Path (eg. /coremio/modules/Payment/SamplePay/)
 $this->lang["example"]        # Calling a field from a language file
 APP_URI                       # Website URL Address
 $this->links["successful"]    # Payment successful page link
 $this->links["failed"]        # Payment failed page link
 $this->links["callback"]      # Callback link

Response

The return value of the function must be an "array" and return the following values.

Name Type Mandatory Explanation
status string Yes The status of the payment may include:
successful : Indicates that the payment was successful.
pending: Indicates that the payment is "pending".
output: It cleans the field where the card information is entered and prints the data in the "output" index.
redirect: It leaves the page and redirects to the specified URL. (Usually used for the "3D Secure" process. You must also use the "callback" method in this process.)
error: Indicates that the payment was unsuccessful.
redirect string No If the status value is set to "redirect", it is mandatory to enter a URL address in this field. After clicking the "Make Payment" button, the customer will be redirected to the URL address specified here.
message string veya array No Used when you need to inform the admin about the payment. (Eg: Number related to tracking the payment) Acceptable value: "array" and "string"
output String No If the status value is defined as "output", the data in this index will be reflected instead of the credit card information entry field.
paid Array No Information of the amount paid [amount] , [currency]
paid [amount] Float Yes Amount of the amount paid
paid[currency] String Yes The currency of the amount paid. Eg: USD,EUR,GBP,TRY

Sample

In the example below, an "HTTP/POST" request is sent to a URL address using the cURL library. After sending the request, the response contains "JSON" output.

public function capture($params=[])
{
    $api_key            = $this->config["settings"]["example1"] ?? 'N/A';
    $secret_key         = $this->config["settings"]["example2"] ?? 'N/A';
    $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_number'        => $params['num'],
            'card_holder_name'   => $params['holder_name'],
            'card_expiry'        => $params['expiry_m']."-".$params['expiry_y'],
            'card_cvc'           => $params['cvc'],
        ],
        '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']],
        ];
    else
        return [
            'status'            => 'error',
            'message'           => $result['error_message'] ?? '!API ERROR!',
        ];

}
Third Party Method Tokenized Method

Do you have any questions?

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