NAME

Business::Eway - eWAY - eCommerce the SAFE and EASY way

SYNOPSIS

use Business::Eway;

my $eway = Business::Eway->new(
    CustomerID => 87654321,
    UserName => 'TestAccount',
);

# when submit the cart order
if ( $submit_order ) {
    my $rtn = $eway->request($args); # $args from CGI params
    if ( $rtn->{Result} eq 'True' ) {
        print $q->redirect( $rtn->{URI} );
    } else {
        die $rtn->{Error};
    }
}
# when user returns back from eway
elsif ( $in_return_or_cancel_page or $params->{AccessPaymentCode} ) {
    my $rtn = $eway->result($AccessPaymentCode);
    if ( $rtn->{TrxnStatus} eq 'true' ) {
        print "Transaction Success!\n";
    } else {
        print "Transaction Failed!\n";
    }
}

DESCRIPTION

eWAY - eCommerce the SAFE and EASY way http://www.eway.co.uk/

new

my $eway = Business::Eway->new(
    CustomerID => 87654321,
    UserName => 'TestAccount',
);
  • CustomerID (required)

  • UserName (required)

    Your eWAY Customer ID and User Name.

  • ua

  • ua_args

    By default, we use LWP::UserAgent->new as the UserAgent. you can pass ua or ua_args to use a different one.

Arguments

All those arguments can be passed into Business::Eway->new() or pass into $eway->request later

  • Amount (required)

    The amount of the transaction in dollar form

    (ie $27.00 transaction would have a Amount value of "27.00")

  • Currency (required)

    Three letter acronym of the currency code according to ISO 4217 (ie British Pound Sterling would be 'GBP')

    Default: 'GBP'

  • ReturnUrl (required)

    The web address to direct the customer with the result of the transaction.

  • CancelURL (required)

    The web address to direct the customer when the transaction is cancelled.

  • PageTitle

    This is value will be displayed as the title of the browser.

    Default: eWAY Hosted Payment Page

  • PageDescription

    This value will be displayed above the Transaction Details.

    Default: Blank

  • PageFooter

    This value will be displayed below the Transaction Details.

  • Language

    The two letter acronym of the language code. supported languages now:

    English  EN 
    Spanish  ES 
    French   FR 
    German   DE 
    Dutch    NL 

    Default: EN

  • CompanyName

    This will be displayed as the company the customer is purchasing from, including this is highly recommended.

  • CompanyLogo

    The url of the image can be hosted on the merchants website and pass the secure https:// path of the image to be displayed at the top of the website. This is the top image block on the webpage and is restricted to 960px X 65px. A default secure image is used if none is supplied.

  • PageBanner

    The url of the image can be hosted on the merchants website and pass the secure https:// path of the image to be displayed at the top of the website. This is the second image block on the webpage and is restricted to 960px X 65px. A default secure image is used if none is supplied.

  • CustomerFirstName

  • CustomerLastName

  • CustomerAddress

  • CustomerCity

  • CustomerState

  • CustomerPostCode

  • CustomerCountry

  • CustomerPhone

  • CustomerEmail

    Customer Information

  • InvoiceDescription

    This field is used to display to the user a description of the purchase they are about to make, usually product summary information.

  • MerchantReference

  • MerchantInvoice

    This is a number created by the merchant for this transaction.

  • MerchantOption1

  • MerchantOption2

  • MerchantOption3

    This field is not displayed to the customer but is returned in the result string. Anything can be used here, useful for tracking transactions

request

my $url = $eway->request_url($args);
my $rtn = $eway->request($args);
my ($status, $url_or_error) = $eway->request($args); # $status 1 - OK, 0 - ERROR

request a URL to https://payment.ewaygateway.com/Request and parse the XML into HASHREF. sample:

$VAR1 = \{
    'Error' => {},
    'URI' => 'https://payment.ewaygateway.com/UK1/PaymentPage.aspx?value=mwm4VNOrYxxxxxx',
    'Result' => 'True'
};

Usually you need redirect to the $rtn->{URI} when Result is True (or $url_or_error when $status is 1).

result

my $url = $eway->result_url($AccessPaymentCode);
my $rtn = $eway->result($AccessPaymentCode);
if ( $rtn->{TrxnStatus} eq 'true' ) {
    print "Transaction Success!\n";
} else {
    print "Transaction Failed!\n";
}
foreach my $k ('TrxnStatus', 'AuthCode', 'ResponseCode', 'ReturnAmount', 'TrxnNumber', 
'TrxnResponseMessage', 'MerchantOption1', 'MerchantOption2', 'MerchantOption3', 
'MerchantInvoice', 'MerchantReference') {
    print "$k: $rtn->{$k}\n";
}

Eway will POST to your ReturnUrl (or CancelURL) when you finish the transaction (or click Cancel button). the POST would contain a param AccessPaymentCode which you can request to get the transaction status.

TIPS

I need params in ReturnUrl

For example, you want your ReturnUrl to be 'http://mysite.com/cgi-bin/cart.cgi?cart_id=ABC'.

you need write the request like:

my $rtn = $eway->request(
    # others
    ReturnUrl => 'http://mysite.com/cgi-bin/cart.cgi',
    MerchantOption1 => 'ABC',
);

and you can get the MerchantOption1 in

my $rtn = $eway->result($AccessPaymentCode);
my $cart_id = $rtn->{MerchantOption1}

EXAMPLES

There is 'examples' directory in the .tar.gz in case you want to have a check.

SEE ALSO

AUTHOR

eWAY Europe Ltd, <support at eway.co.uk>

COPYRIGHT & LICENSE

Copyright 2009 eWAY Europe Ltd.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.