Showing posts with label credit card payment. Show all posts
Showing posts with label credit card payment. Show all posts

Saturday, June 10, 2017

PayWay Rest API: Create Credit Card Payment

If you are not already check connection to PayWay Rest API, you need to do that validation. Follow the below link to test API connection, there you can learn about public and private key.


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 credit card payment. 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_...");

createPayment(getSingleUseToken());

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

    $post = array(
        "singleUseTokenId" => $token,
        "customerNumber" => "Customer-ID",
        "transactionType" => "payment",
        "principalAmount" => "12.34",
        "currency" => "aud",
        "orderNumber" => "Sale-Identification",
        "merchantId" => MERCHANT_ID
    );

    $result = CurlExecutor::execute(BASE_URL . "/transactions", "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");
}
?>



Below is output of valid payment:


Array
(
    [code] => 201
    [response] => stdClass Object
        (
            [transactionId] => 1957973936
            [receiptNumber] => 1957973936
            [status] => approved
            [responseCode] => 08
            [responseText] => Honour with identification
            [transactionType] => payment
            [customerNumber] => CUSTOMER-ID
            [customerName] => My Mastercard
            [orderNumber] => Sale-Identification
            [currency] => aud
            [principalAmount] => 12.34
            [surchargeAmount] => 0
            [paymentAmount] => 12.34
            [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 11:57 AEST
            [settlementDate] => 10 Jun 2017
            [isVoidable] => 1
            [isRefundable] => 
            [links] => Array
                (
                    [0] => stdClass Object
                        (
                            [rel] => self
                            [href] => https://api.payway.com.au/rest/v1/transactions/1957973936
                        )

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

                )

        )

)

And you can see that in PayWay portal there is a payment created:


Error response from PayWay Rest API is well defined. So you can capture error response easily.


Tuesday, February 4, 2014

Secure pay xml api credit card payment


<?php 
#Test Merchant ID: abc0001
#Test Merchant Password: acb123
#Test URL (no SSL):     http://test.securepay.com.au/xmlapi/payment
#Test URL (SSL):        https://test.securepay.com.au/xmlapi/payment
#Live URL:              https://api.securepay.com.au/xmlapi/payment
$xml = '<?xml version="1.0" encoding="UTF-8"?>
    <SecurePayMessage>
        <MessageInfo>
            <messageID>8af793f9af34bea0cf40f5fb5c630c</messageID>
            <messageTimestamp>20041803161306527000+660</messageTimestamp>
            <timeoutValue>60</timeoutValue>
            <apiVersion>xml-4.2</apiVersion>
        </MessageInfo>
        <MerchantInfo>
            <merchantID>abc0001</merchantID>
            <password>abc123</password>
        </MerchantInfo>
        <RequestType>Payment</RequestType>
        <Payment>
            <TxnList count="1">
                <Txn ID="1">
                    <txnType>0</txnType>
                    <txnSource>0</txnSource>
                    <amount>1000</amount>
                    <currency>AUD</currency>
                    <purchaseOrderNo>test</purchaseOrderNo>
                    <CreditCardInfo>
                        <cardNumber>4444333322221111</cardNumber>
                        <expiryDate>09/15</expiryDate>
                    </CreditCardInfo>
                </Txn>
            </TxnList>
        </Payment>
    </SecurePayMessage>';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://test.securepay.com.au/xmlapi/payment");
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); // Follow redirects
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); // Return the HTTP response from the curl_exec function

$response = curl_exec($curl);
curl_close($curl);

header('Content-type: text/xml');
echo $response;

$responseIsLikeThis = '
<SecurePayMessage>
    <MessageInfo>
        <messageID>8af793f9af34bea0cf40f5fb5c630c</messageID>
        <messageTimestamp>20140402171039522000+660</messageTimestamp>
        <apiVersion>xml-4.2</apiVersion>
    </MessageInfo>
    <RequestType>Payment</RequestType>
    <MerchantInfo>
        <merchantID>ABC0001</merchantID>
    </MerchantInfo>
    <Status>
        <statusCode>000</statusCode>
        <statusDescription>Normal</statusDescription>
    </Status>
    <Payment>
        <TxnList count="1">
            <Txn ID="1">
                <txnType>0</txnType>
                <txnSource>0</txnSource>
                <amount>1000</amount>
                <currency>AUD</currency>
                <purchaseOrderNo>test</purchaseOrderNo>
                <approved>Yes</approved>
                <responseCode>00</responseCode>
                <responseText>Approved</responseText>
                <thinlinkResponseCode>100</thinlinkResponseCode>
                <thinlinkResponseText>000</thinlinkResponseText>
                <thinlinkEventStatusCode>000</thinlinkEventStatusCode>
                <thinlinkEventStatusText>Normal</thinlinkEventStatusText>
                <settlementDate>20140204</settlementDate>
                <txnID>576566</txnID>
                <CreditCardInfo>
                    <pan>444433...111</pan>
                    <expiryDate>09/15</expiryDate>
                    <cardType>6</cardType>
                    <cardDescription>Visa</cardDescription>
                </CreditCardInfo>
            </Txn>
        </TxnList>
    </Payment>
</SecurePayMessage>';
?>