Simple SDKs

eWAY is the easiest way to accept payments in your app or on your website. Get integrated and start selling more, faster - in a range of languages using the eWAY SDKs, helpful documentation, and 24/7 support from real humans. eWAY - with you every step of the way.

PHP SDK

Accept payments quickly and easily with eWAY using the eWAY Rapid PHP SDK. Using the PHP SDK provides convenient access to all the features of eWAY’s Rapid API, so you can create transactions, process refunds, query transactions, create token customers, and more!

Getting Started


Requirements

The eWAY PHP SDK requires PHP version 5.4.0 or greater with the curl, json and openssl extensions. We recommend installing using the Composer Package Manager. 

To make development and testing with eWAY easy, get a free partner account which provides access to the eWAY Sandbox. To find out more about activating Sandbox, check out the Success Community article here.  

Install

With Composer
If you have Composer, adding the eWAY PHP SDK is as simple as running the following on the command line:

  1. $ composer require eway/eway-rapid-php
Once ​installed, the eWAY PHP SDK can be loaded in your project using Composer’s autoloader:

  1. <?php

  2. require('vendor/autoload.php');
Manual Install

If you don’t have access to Composer, you can add the eWAY PHP SDK to your project by:

  1. Download the latest zip
  2. Unzip the zip into your project – for example into a lib directory
  3. Include the eWAY SDK:
    1. <?php

    2. require_once 'lib/eway-rapid-php-master/include_eway.php';

Now you are all set to build your eWAY integration! You can find code samples for integrating various eWAY functions as part of the eWAY Rapid API reference.


Example Integration

To demonstrate using the eWAY PHP SDK, this example will show how to accept a payment with the Responsive Shared Page

This example assumes that Composer is already installed and a new project is being started. 



1. Add the eWAY PHP SDK


In the project directory, run the Composer command to install the eWAY PHP SDK. 

  1. $ composer require eway/eway-rapid-php

Once completed, the directory should now have a “vendor” folder, along with a couple of composer files. 


2. Load the eWAY PHP SDK

Create an index.php file in the project directory and add the Composer autoloader:

  1. <?php

  2. require('vendor/autoload.php');

Now the eWAY client can be created with your Rapid API key & password. These can be found in Sandbox or Live MYeWAY – remember that different credentials are needed for Sandbox Live.  

 
  1. // eWAY Credentials
  2. $apiKey = '60CF3Ce97nRS1Z1Wp5m9kMmzHHEh8Rkuj31QCtVxjPWGYA9FymyqsK0Enm1P6mHJf0THbR';
  3. $apiPassword = 'API-P4ss';
  4. $apiEndpoint = 'Sandbox';

  5. // Create the eWAY Client
  6. $client = \Eway\Rapid::createClient($apiKey, $apiPassword, $apiEndpoint);


3. Create a Shared Payment URL


In order to send a customer to the Responsive Shared Page, a URL must be generated using the
createTransaction function. This accepts a PaymentMethod and an array of transaction data.

The PaymentMethod determines how the card data will be accepted (in this case ResponsiveShared) while the transaction array contains customer and invoice details – more details of the variables that can be passed can be found in the Rapid API reference

This step would usually take place after collecting the customer’s information in a checkout process. For this example, just some dummy data will be used:
 
  1. // Transaction details - these would usually come from the application
  2. $transaction = [
  3.     'Customer' => [
  4.         'FirstName' => 'John',
  5.         'LastName' => 'Smith',
  6.         'Street1' => 'Level 5',
  7.         'Street2' => '369 Queen Street',
  8.         'City' => 'Sydney',
  9.         'State' => 'NSW',
  10.         'PostalCode' => '2000',
  11.         'Country' => 'au',
  12.         'Email' => 'demo@example.org',
  13.     ],
  14.     // These should be set to your actual website (on HTTPS of course)
  15.     'RedirectUrl' => "http://$_SERVER[HTTP_HOST]" . dirname($_SERVER['REQUEST_URI']) . '/response.php',
  16.     'CancelUrl' => "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]",
  17.     'TransactionType' => \Eway\Rapid\Enum\TransactionType::PURCHASE,
  18.     'Payment' => [
  19.         'TotalAmount' => 1000,
  20.     ]
  21. ];

  22. // Submit data to eWAY to get a Shared Page URL
  23. $response = $client->createTransaction(\Eway\Rapid\Enum\ApiMethod::RESPONSIVE_SHARED, $transaction);


To make sure everything went well, check that the Errors list is empty. If it isn’t, UserDisplayMessage can be used to convert any error codes to human readable messages:

 
  1. // Check for any errors
  2. if (!$response->getErrors()) {
  3.     $sharedURL = $response->SharedPaymentUrl;
  4. } else {
  5.     foreach ($response->getErrors() as $error) {
  6.         echo "Error: ".\Eway\Rapid::getMessage($error)."<br>";
  7.     }
  8.     die();
  9. }
 

 

4. ​Redirect the Customer


Usually once the shared page URL has been created, the customer can be immediately redirected. For this example we’ll just display a link:

 
  1. echo '<a href="'.$sharedURL.'">Pay with our secure payment page</a>';
You should now be able to visit the index.php file in your web browser – it will display a link which goes to the Responsive Shared Page created with the details submitted in the previous step.

 

5. ​​Fetch the Result

Once the customer has gone to the Responsive Shared Page and submitted their payment information, they will be redirected back to the RedirectUrl specified in the request. This was set to response.php – so now create that file and insert the following to fetch the transaction result:

  1. require('vendor/autoload.php');

  2. // eWAY Credentials
  3. $apiKey = '60CF3Ce97nRS1Z1Wp5m9kMmzHHEh8Rkuj31QCtVxjPWGYA9FymyqsK0Enm1P6mHJf0THbR';
  4. $apiPassword = 'API-P4ss';
  5. $apiEndpoint = \Eway\Rapid\Client::MODE_SANDBOX;

  6. // Create the eWAY Client
  7. $client = \Eway\Rapid::createClient($apiKey, $apiPassword, $apiEndpoint);

  8. // Query the transaction result.
  9. $response = $client->queryTransaction($_GET['AccessCode']);

Key information such as the success of the transaction and the transaction ID can be found in the TransactionStatus of the response. If the transaction wasn’t successful, the reason can be found in the ResponseMessage. An example of handling this information would be


  1. $transactionResponse = $response->Transactions[0];

  2. // Display the transaction result
  3. if ($transactionResponse->TransactionStatus) {
  4.     echo 'Payment successful! ID: ' .
  5.         $transactionResponse->TransactionID;
  6. } else {
  7.     $errors = split(', ', $transactionResponse->ResponseMessage);
  8.     foreach ($errors as $error) {
  9.         echo "Payment failed: " .
  10.             \Eway\Rapid::getMessage($error)."<br>";
  11.     }
  12. }

 

That’s it – you should now be able to visit the index.php file on your server and complete a payment with the Responsive Shared Page!


For more information on the functions available in the eWAY PHP SDK, check out the eWAY Rapid API reference
 

eWAY makes it easy for us to process and manage payments. They have an SDK that my developers liked working with and their payment management tools are very easy to use.

Dean Van Es, Managing Director FastCover