Payment Widget
Coming soon!

Payment Widget Integration

You can easily integrate 2000Charge's Payment Widget which enables all the necessary processes for making a fast, secure, simple and personalized checkout.

Click on "Pay with 2000Charge" to see our Payment Widget in live mode. If you want to see how it works, you need to fill out the required fields to complete the transaction.


Tokenization

Payments processed by 2000Charge are Tokenized and use SSL Encryption. Sensitive payment information is automatically converted to a uniqe token which is sent to our secure servers for validation. All sensitive consumer data that should not be stored, transferred or logged on your server for security reasons is securely processed by our company with the highest PCI security standards.

Widget Flow

Local Payments Widget Flow

How to implement

To get started, please download to your widget folder on your server 2000Charge php-sdk from our github page.

Next, you are required to add the following code to your page.

You must insert your API keys. After the registration process you will be provided with the API Test Keys and API Production Keys, the parameters needed for start accepting payments through our payment system.

NOTE: Production API Keys are avaliable once you are verified, and are used to proccess live transactions.

Where do I find my keys?

You can find your test and production API keys under the Development menu item in the Merchant Portal.

There you can find your:

1.Test Public Key & Test Secret Key

2.Production Secret Key & Production Public Key


<?php require_once 'ap-php-sdk/vendor/autoload.php';

use 2000Charge\Config;

// Set Private and Public Key
Config :: setApiKey("abcdefghijkl123456");
$publicKey = "abcdefghijkl123456";

// Set API url
Config :: setApiUrl("https://api.2000Charge.com/api");


$currency = "USD";
$amount = "9.54";

$productDescription = "Red T-shirt";

$successUrl = "http://2000charge.com/message/success.html";
$cancelUrl = "http://2000charge.com/message/failure.html";


$error = '';
$success = '';
$formPost = $_POST;

// Function to get the client IP address
function get_client_ip() {
    $ipaddress = '';
    if (isset($_SERVER['HTTP_CLIENT_IP']))
        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_X_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if(isset($_SERVER['REMOTE_ADDR']))
        $ipaddress = $_SERVER['REMOTE_ADDR'];
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}

if ($formPost) {
    try {
        //Check if js returns the token
        if (!isset($formPost["APToken"])){
            throw new Exception("The AP Token was not generated correctly");
        }
        $customer = new \2000Charge\Model\Customer();
        $customer->setEmail($formPost["APEmail"]);
        $customer->setFirstName($formPost["APFirstName"]);
        $customer->setLastName($formPost["APLastName"]);
        $customer->setCountry($formPost["APCountry"]);
        
        $customer->setState(isset($formPost["APState"]) ? $formPost["APState"] : null);
        $customer->setAddress(isset($formPost["APAddress"]) ? $formPost["APAddress"] : null);
        $customer->setAddress2(isset($formPost["APAddress2"]) ? $formPost["APAddress2"] : null);
        $customer->setCity(isset($formPost["APCity"]) ? $formPost["APCity"] : null);
        $customer->setZip(isset($formPost["APZip"]) ? $formPost["APZip"] : null);
        $customer->setBirthDate(isset($formPost["APBirthDate"]) ? $formPost["APBirthDate"] : null);
        if (isset($formPost["APPhone"]))
            $customer->setPhone($formPost["APPhone"]);
        //fixed fields
        
        $transaction = new \2000Charge\Model\Transaction();
        $transaction->setAmount($amount * 100);
        $transaction->setCurrency($currency);
        $transaction->setToken($formPost["APToken"]);
        $transaction->setDescription($productDescription);
        $transaction->setIPAddress(get_client_ip());

        if (isset($formPost["APPhoneVerificationPin"]) && isset($formPost["APPhoneVerificationToken"])){
            $phoneVerification = new \2000Charge\Model\PhoneVerification();
            $phoneVerification->setPin($formPost["APPhoneVerificationPin"]);
            $phoneVerification->setToken($formPost["APPhoneVerificationToken"]);
            $transaction->setPhoneVerification($phoneVerification);

        }
        
        $redirectUrls = new \2000Charge\Model\RedirectUrls();
        $redirectUrls->setReturnUrl($successUrl);
        $redirectUrls->setCancelUrl($cancelUrl);
        $transaction->setRedirectUrls($redirectUrls);
        
        $transaction->setCustomer($customer);
        
        $result = \2000Charge\Transaction::post($transaction);
        
    //  var_dump($result);
        
        if (array_key_exists('Message', $result)) {
            $error = '<p>' . $result['Message'] . '</p>';
        }
        else {
            $success = '<p>Your payment was successful.</p>';
            $resultArray = json_decode(json_encode($result), true);
            $selectedpaymentoption = $resultArray["payment"]["paymentOption"];
            switch ($selectedpaymentoption) {
                case "SEPA":
                    header('Location: '.$successUrl);
                    break;
                default:
                    $redirectingurl = $resultArray["redirectUrl"];
                    header('Location: '.$redirectingurl);
                                    }       
        }
    }
    catch (Exception $e) {
        $error = 'Error: '.$e->getMessage();
    }
}
?>