Skip to content

Instantly share code, notes, and snippets.

@incarnate
Last active September 4, 2016 02:13
Show Gist options
  • Save incarnate/fab4af9f0059fe405eaa to your computer and use it in GitHub Desktop.
Save incarnate/fab4af9f0059fe405eaa to your computer and use it in GitHub Desktop.

eWAY PHP Library

THIS IS A DRAFT OF THE GITHUB eWAY PHP API README!

This library provides integration with the eWAY payment gateway Rapid API 3.1.

Requirements

  • PHP 5.3 or greater
  • cURL extension

Basic examples

The following are basic examples using the minimal number of inputs.

Responsive Shared Page

Using eWAY's Responsive Shared Page, your customer is directed to eWAY's secure hosted page to input their credit card details. This means no PCI compliance hassle for you!

This is done with a two step process, for more information see the full documentation.

  1. Pass the transaction information to eWAY to generate the shared page URL

    <?php
    require('lib/eWAY/RapidAPI.php');
    
    $request = new eWAY\CreateAccessCodesSharedRequest();
    
    $request->Payment->TotalAmount = '100'; // Amount is in cents, 100 = $1.00
    $request->RedirectUrl = 'http://example.com/complete';
    
    $service = new eWAY\RapidAPI(
        'eWAY API key', 
        'eWAY API password', 
        array('sandbox' => false)
    );
    
    // Get the AccessCode
    $result = $service->CreateAccessCodesShared($request);
    
    // Send the customer to eWAY to pay
    header("Location: " . $result->SharedPaymentUrl);
    exit();
  2. Once the payment is completed, the customer comes back to what you set as the RedirectUrl. The URL has an AccessCode passed as a parameter you can use to look up if the transaction succeeded

    <?php
    require('lib/eWAY/RapidAPI.php');
    
    $request = new eWAY\GetAccessCodeResultRequest();
    $request->AccessCode = $_GET['AccessCode'];
    
    $service = new eWAY\RapidAPI(
        'eWAY API key', 
        'eWAY API password', 
        array('sandbox' => false)
    );
    
    $result = $service->GetAccessCodeResult($request);

Transparent Redirect

With Transparent Redirect, the customer fills in their credit card details on your website and the form submits directly to eWAY to handle the payment. Once the payment is processed, they are sent directly back to your website.

This method doesn't require your server be PCI Compliant, however an SSL certificate is necessary.

Using eWAY Transparent Redirect is a three step process, for more information see the full documentation

  1. Get the submission URL

    <?php
    require('lib/eWAY/RapidAPI.php');
    
    $request = new eWAY\CreateAccessCodeRequest();
    $request->Payment->TotalAmount = '100'; // Amount is in cents, 100 = $1.00
    $request->RedirectUrl = 'http://example.com/complete';
    
    $service = new eWAY\RapidAPI(
        'eWAY API key', 
        'eWAY API password', 
        array('sandbox' => false)
    );
    
    $result = $service->CreateAccessCode($request);
  2. Generate the form for the customer

    <form method="POST" action="<?php echo $result->FormActionURL ?>">
        <input type="hidden" name="EWAY_ACCESSCODE" value="<?php echo $result->AccessCode ?>" />
        <input type="hidden" name="EWAY_PAYMENTTYPE" value="Credit Card" />
        <input type="text" name="EWAY_CARDNAME" />
        <input type="text" name="EWAY_CARDNUMBER" />
        <input type="text" name="EWAY_CARDEXPIRYMONTH" />
        <input type="text" name="EWAY_CARDEXPIRYYEAR" />
        <input type="text" name="EWAY_CARDCVN" />
        <input type="submit" value="Process" text="Process" />
     </form> 
  3. Once the payment is completed, the customer comes back to what you set as the RedirectUrl. The URL has an AccessCode passed as a parameter you can use to look up if the transaction succeeded

    <?php
    require('lib/eWAY/RapidAPI.php');
    
    $request = new eWAY\GetAccessCodeResultRequest();
    $request->AccessCode = $_GET['AccessCode'];
    
    $service = new eWAY\RapidAPI(
        'eWAY API key', 
        'eWAY API password', 
        array('sandbox' => false)
    );
    
    $result = $service->GetAccessCodeResult($request);

Direct Payment

Direct payments allows you to submit a payment directly to eWAY from your website.

Before being able to send credit card data via the direct API, eWAY must enable it on the account. To be enabled on a live account eWAY must receive proof that your server is PCI-DSS compliant. Alternatively, you can use client side encryption so that the card details are encrypted when they are passed to your server.

Submitting a Direct Payment is a simple one step process, see the full documentation for more information.

<?php
require('lib/eWAY/RapidAPI.php');

$request = new eWAY\CreateDirectPaymentRequest();

$request->Payment->TotalAmount = '100'; // Amount is in cents, 100 = $1.00
$request->Customer->CardDetails->Number = 'XXXXXXXXXXXX';
$request->Customer->CardDetails->ExpiryMonth = '05';
$request->Customer->CardDetails->ExpiryYear = '19';
$request->Customer->CardDetails->CVN = '123';

$service = new eWAY\RapidAPI(
    'eWAY API key', 
    'eWAY API password', 
    array('sandbox' => false)
);

$result = $service->DirectPayment($request);

Documentation

Handy Links

@incarnate
Copy link
Author

Please note this doco references an older version of the eWAY PHP sample code.

See the eWAY PHP SDK for the latest and greatest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment