Showing posts with label refund. Show all posts
Showing posts with label refund. 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
                        )

                )

        )

)





Wednesday, August 7, 2013

Refund transaction using php api using eWay account

/* Refund using eWay */
function refund_using_eway()
{
    $testUrl = "https://www.eway.com.au/gateway/xmltest/refund_test.asp";
    $liveUrl = "https://www.eway.com.au/gateway/xmlpaymentrefund.asp";

    $eWaySOAPActionURL = "https://www.eway.com.au/gateway/managedpayment";
    $eWayCustomerId = "87654321";
    $eWayTotalAmount = 100;
    $directXML = "<ewaygateway>" .
        "<ewayCustomerID>" . $eWayCustomerId . "</ewayCustomerID>" .
        "<ewayOriginalTrxnNumber>20488</ewayOriginalTrxnNumber>" .
        "<ewayTotalAmount>" . $eWayTotalAmount . "</ewayTotalAmount>" .
        "<ewayCardExpiryMonth>01</ewayCardExpiryMonth>" .
        "<ewayCardExpiryYear>2015</ewayCardExpiryYear>" .
        "<ewayOption1></ewayOption1>" .
        "<ewayOption2></ewayOption2>" .
        "<ewayOption3></ewayOption3>" .
        "<ewayRefundPassword>test123</ewayRefundPassword>" .
        "</ewaygateway>";

    $result = makeCurlCall(
        $testUrl, /* CURL URL */
        "POST", /* CURL CALL METHOD */
        array( /* CURL HEADERS */
            "Content-Type: text/xml; charset=utf-8",
            "Accept: text/xml",
            "Pragma: no-cache",
            "SOAPAction: " . $eWaySOAPActionURL,
            "Content_length: " . strlen(trim($directXML))
        ),
        null, /* CURL GET PARAMETERS */
        $directXML /* CURL POST PARAMETERS AS XML */
    );

    if ($result != null && isset($result["response"])) {
        $response = new SimpleXMLElement($result["response"]);
        $response = simpleXMLToArray($response);
        print_r2($response);
    }
    die("");
}

/* makeCurlCall */
function makeCurlCall($url, $method = "GET", $headers = null, $gets = null, $posts = null) {
    $ch = curl_init();
    if($gets != null)
    {
        $url.="?".(http_build_query($gets));
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    if($posts != null)
    {
        curl_setopt($ch, CURLOPT_POSTFIELDS, $posts);
    }
    if($method == "POST") {
        curl_setopt($ch, CURLOPT_POST, true);
    } else if($method == "PUT") {
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    } else if($method == "HEAD") {
        curl_setopt($ch, CURLOPT_NOBODY, true);
    }
    if($headers != null && is_array($headers))
    {
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    }
    $response = curl_exec($ch);
    $code = curl_getinfo($ch,CURLINFO_HTTP_CODE);

    curl_close($ch);
    return array(
        "code" => $code,
        "response" => $response
    );
}

/* Response */
Array
(
    [ewayTrxnStatus] => Array
        (
            [__cdata] => False
        )

    [ewayTrxnNumber] => Array
        (
            [__cdata] =>
        )

    [ewayTrxnOption1] => Array
        (
            [__cdata] =>
        )

    [ewayTrxnOption2] => Array
        (
            [__cdata] =>
        )

    [ewayTrxnOption3] => Array
        (
            [__cdata] =>
        )

    [ewayAuthCode] => Array
        (
            [__cdata] =>
        )

    [ewayReturnAmount] => Array
        (
            [__cdata] => 100
        )

    [ewayTrxnError] => Array
        (
            [__cdata] => Error: Invalid Original Transaction Number. Your credit card has not been billed for this transaction.
        )

)

/* Dont worry about ewayTrxnError, when you refund live it will work */