Showing posts with label PayWay Check Rest Credentials. Show all posts
Showing posts with label PayWay Check Rest Credentials. Show all posts

Saturday, June 10, 2017

PayWay Rest API: Create Refund From PayWay Payment

You can visit PayWay rest api documentation page:
https://www.payway.com.au/docs/rest.html#refund-a-payment

PayWay Rest API: Check if Rest API credentials are valid

PayWay Rest API: Create Customer Create 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_...");

createRefundOfPayment();

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

    $post = array(
        "parentTransactionId" => "1956258559",
        "transactionType" => "refund",
        "principalAmount" => "23.45",
        "orderNumber" => "RefundIdentification"
    );

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


And output is below:


Array
(
    [code] => 201
    [response] => stdClass Object
        (
            [transactionId] => 1958000143
            [receiptNumber] => 1958000143
            [status] => approved
            [responseCode] => 08
            [responseText] => Honour with identification
            [transactionType] => refund
            [customerNumber] => 5
            [customerName] => Hexa Lucio
            [customerEmail] => hexa@bitmascot.com
            [orderNumber] => RefundIdentification
            [currency] => aud
            [principalAmount] => -23.45
            [surchargeAmount] => 0
            [paymentAmount] => -23.45
            [paymentMethod] => creditCard
            [creditCard] => stdClass Object
                (
                    [cardNumber] => 456471...004
                    [expiryDateMonth] => 02
                    [expiryDateYear] => 19
                    [cardScheme] => visa
                    [cardholderName] => Hexa Lucio Tony
                )

            [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:24 AEST
            [settlementDate] => 10 Jun 2017
            [parentTransaction] => stdClass Object
                (
                    [transactionId] => 1956258559
                    [receiptNumber] => 1956258559
                    [status] => approved
                    [transactionType] => payment
                    [customerNumber] => 5
                    [orderNumber] => INV-GGO-ABA-460
                    [currency] => aud
                    [paymentAmount] => 99.25
                    [settlementDate] => 08 Jun 2017
                )

            [isVoidable] => 1
            [isRefundable] => 
            [links] => Array
                (
                    [0] => stdClass Object
                        (
                            [rel] => self
                            [href] => https://api.payway.com.au/rest/v1/transactions/1958000143
                        )

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

                    [2] => stdClass Object
                        (
                            [rel] => parent
                            [href] => https://api.payway.com.au/rest/v1/transactions/1956258559
                        )

                )

        )

)





PayWay Rest API: Check if Rest API credentials are valid

PayWay Rest API is easy to implement. We need three information from PayWay end to create payment, refund payment, void payment, store credit card for further use and many other things.

So we need:
1. Publishable public key
2. Secret private key



3. and Merchant ID



Now you have all 3 information to communicate with PayWay.

Below is a PHP script to test credentials using rest API:


<?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_...");

$headers[] = "Authorization: Basic " . base64_encode(PUBLIC_KEY . ":");
$result = CurlExecutor::execute(BASE_URL, "GET", null, null, $headers);
$result["response"] = json_decode($result["response"]);
CurlExecutor::prettyPrint($result);
?>


If your credentials are fine below output will back from PayWay end:


Array
(
    [code] => 200
    [response] => stdClass Object
        (
            [clientNumber] => T52943
            [clientName] => Pritom
            [keyName] => T10487_PUB...bzq
            [links] => Array
                (
                    [0] => stdClass Object
                        (
                            [rel] => single-use-tokens
                            [href] => https://api.payway.com.au/rest/v1/single-use-tokens
                        )

                    [1] => stdClass Object
                        (
                            [rel] => surcharges
                            [href] => https://api.payway.com.au/rest/v1/surcharges
                        )

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

                )

        )

)
If you have error in your public key below output will be generated:


Array
(
    [code] => 401
    [response] => stdClass Object
        (
            [message] => The "Authorization" header contained an unknown API key. You must send your API key as the basic authentication username.
            [links] => Array
                (
                    [0] => stdClass Object
                        (
                            [rel] => help
                            [href] => https://www.payway.com.au/docs/rest.html#authentication
                        )

                )

        )

)