Showing posts with label PayWay Customer. Show all posts
Showing posts with label PayWay Customer. Show all posts

Saturday, June 10, 2017

PayWay Rest API: Create Payment Using Stored Credit Card Token

It's easy to store credit card in PayWay and create payment using that that credit card token.

PayWay Rest API: Check if Rest API credentials are valid

PayWay Rest API: Create Customer Create Token

Below is a PHP script to create payment using stored credit card token:


<?php
include_once "CurlExecutor.php";

define("BASE_URL", "https://api.payway.com.au/rest/v1");
define("MERCHANT_ID", "TEST");
define("PRIVATE_KEY", "T10487_SEC_...");
define("PUBLIC_KEY", "T10487_PUB_...");

createTokenPayment();

function createTokenPayment() {
    $headers[] = "Authorization: Basic " . base64_encode(PRIVATE_KEY . ":");
    $headers[] = "Content-Type: application/x-www-form-urlencoded";

    $post = array(
        "customerNumber" => 7,
        "merchantId" => MERCHANT_ID,
        "transactionType" => "payment",
        "principalAmount" => "23.45",
        "currency" => "aud",
        "orderNumber" => "Sale-Identification"
    );

    $result = CurlExecutor::execute(BASE_URL . "/transactions", "POST", $post, null, $headers);
    $result["response"] = json_decode($result["response"]);
    CurlExecutor::prettyPrint($result);
}
?>

Output as below:


Array
(
    [code] => 201
    [response] => stdClass Object
        (
            [transactionId] => 1957977083
            [receiptNumber] => 1957977083
            [status] => approved
            [responseCode] => 08
            [responseText] => Honour with identification
            [transactionType] => payment
            [customerNumber] => 7
            [customerName] => Pritom
            [customerEmail] => pritomkucse@gmail.com
            [orderNumber] => Sale-Identification
            [currency] => aud
            [principalAmount] => 23.45
            [surchargeAmount] => 0
            [paymentAmount] => 23.45
            [paymentMethod] => creditCard
            [creditCard] => stdClass Object
                (
                    [cardNumber] => 516320...008
                    [expiryDateMonth] => 08
                    [expiryDateYear] => 20
                    [cardScheme] => mastercard
                    [cardholderName] => My Mastercard
                )

            [merchant] => stdClass Object
                (
                    [merchantId] => TEST
                    [merchantName] => Test Merchant
                    [links] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [rel] => self
                                    [href] => https://api.payway.com.au/rest/v1/merchants/TEST
                                )

                        )

                )

            [transactionDateTime] => 10 Jun 2017 13:09 AEST
            [settlementDate] => 10 Jun 2017
            [isVoidable] => 1
            [isRefundable] => 
            [links] => Array
                (
                    [0] => stdClass Object
                        (
                            [rel] => self
                            [href] => https://api.payway.com.au/rest/v1/transactions/1957977083
                        )

                    [1] => stdClass Object
                        (
                            [rel] => void
                            [href] => https://api.payway.com.au/transactions/1957977083/void
                        )

                )

        )

)








PayWay Rest API: Create Customer Create Token

You can create token in PayWay portal using credit card details to use further that token to create payment.

PayWay Rest API: Check if Rest API credentials are valid

If you are interested more on PayWay Rest API you can visit the below link:

https://www.payway.com.au/docs/rest.html

Below is a PHP script to create token using credit card etails. Be aware that below code snippet used both private and public key in different section.



<?php
include_once "CurlExecutor.php";

define("BASE_URL", "https://api.payway.com.au/rest/v1");
define("MERCHANT_ID", "TEST");
define("PRIVATE_KEY", "T10487_SEC_...");
define("PUBLIC_KEY", "T10487_PUB_...");

createCustomer(getSingleUseToken());

function createCustomer($token) {
    $headers[] = "Authorization: Basic " . base64_encode(PRIVATE_KEY . ":");
    $headers[] = "Content-Type: application/x-www-form-urlencoded";

    $post = array(
        "singleUseTokenId" => $token,
        "merchantId" => MERCHANT_ID,
        "customerName" => "Pritom",
        "emailAddress" => "pritomkucse@gmail.com"
    );

    $result = CurlExecutor::execute(BASE_URL . "/customers", "POST", $post, null, $headers);
    $result["response"] = json_decode($result["response"]);
    CurlExecutor::prettyPrint($result);
}

function getSingleUseToken() {
    $headers[] = "Authorization: Basic " . base64_encode(PUBLIC_KEY . ":");
    $headers[] = "Content-Type: application/x-www-form-urlencoded";

    $post = array(
        "paymentMethod" => "creditCard",
        "cardNumber" => "5163200000000008",
        "cardholderName" => "My Mastercard",
        "cvn" => "070",
        "expiryDateMonth" => "08",
        "expiryDateYear" => "20",
    );

    $result = CurlExecutor::execute(BASE_URL . "/single-use-tokens", "POST", $post, null, $headers);
    $result["response"] = json_decode($result["response"]);
    if ($result["code"] == 200) {
        return $result["response"]->singleUseTokenId;
    }
    CurlExecutor::prettyPrint($result);
    die("Error");
}
?>

Output is below:


Array
(
    [code] => 201
    [response] => stdClass Object
        (
            [customerNumber] => 7
            [paymentSetup] => stdClass Object
                (
                    [paymentMethod] => creditCard
                    [stopped] => 
                    [creditCard] => stdClass Object
                        (
                            [cardNumber] => 516320...008
                            [expiryDateMonth] => 08
                            [expiryDateYear] => 20
                            [cardScheme] => mastercard
                            [cardholderName] => My Mastercard
                            [surchargePercentage] => 0
                        )

                    [merchant] => stdClass Object
                        (
                            [merchantId] => TEST
                            [merchantName] => Test Merchant
                            [links] => Array
                                (
                                    [0] => stdClass Object
                                        (
                                            [rel] => self
                                            [href] => https://api.payway.com.au/rest/v1/merchants/TEST
                                        )

                                )

                        )

                )

            [contact] => stdClass Object
                (
                    [customerName] => Pritom
                    [emailAddress] => pritomkucse@gmail.com
                    [sendEmailReceipts] => 
                    [phoneNumber] => 
                    [address] => stdClass Object
                        (
                            [street1] => 
                            [street2] => 
                            [cityName] => 
                            [state] => 
                            [postalCode] => 
                        )

                )

            [customFields] => stdClass Object
                (
                )

            [links] => Array
                (
                    [0] => stdClass Object
                        (
                            [rel] => self
                            [href] => https://api.payway.com.au/rest/v1/customers/7
                        )

                    [1] => stdClass Object
                        (
                            [rel] => help
                            [href] => https://www.payway.com.au/docs/rest.html#customers
                        )

                    [2] => stdClass Object
                        (
                            [rel] => contact
                            [href] => https://api.payway.com.au/rest/v1/customers/7/contact
                        )

                    [3] => stdClass Object
                        (
                            [rel] => custom-fields
                            [href] => https://api.payway.com.au/rest/v1/customers/7/custom-fields
                        )

                    [4] => stdClass Object
                        (
                            [rel] => payment-setup
                            [href] => https://api.payway.com.au/rest/v1/customers/7/payment-setup
                        )

                    [5] => stdClass Object
                        (
                            [rel] => schedule
                            [href] => https://api.payway.com.au/rest/v1/customers/7/schedule
                        )

                    [6] => stdClass Object
                        (
                            [rel] => virtual-account
                            [href] => https://api.payway.com.au/rest/v1/customers/7/virtual-account
                        )

                    [7] => stdClass Object
                        (
                            [rel] => search-customer-transactions
                            [href] => https://api.payway.com.au/rest/v1/transactions/search-customer?customerNumber=7
                        )

                )

        )

)