Saturday, June 10, 2017

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
                        )

                )

        )

)


No comments:

Post a Comment