Fayland 林 > Business-eWAY-RapidAPI > Business::eWAY::RapidAPI

Download:
Business-eWAY-RapidAPI-0.06.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.06   Source  

NAME ^

Business::eWAY::RapidAPI - eWAY RapidAPI V3

VERSION ^

version 0.06

SYNOPSIS ^

    use Business::eWAY::RapidAPI;

    my $rapidapi = Business::eWAY::RapidAPI->new(
        username => "44DD7C70Jre1dVgIsULcEyi+A+/cX9V5SAHkIiyVdWrHRG2tZm0rdintfZz85Pa/kGwq/1",
        password => "Abcd1234",
    );

DESCRIPTION ^

eWAY RapidAPI http://www.eway.com.au/developers/api/rapid-3-0

check https://github.com/fayland/p5-Business-eWAY-RapidAPI/tree/master/examples/web for usage demo.

METHODS

CONSTRUCTION

    my $rapidapi = Business::eWAY::RapidAPI->new(
        mode => 'test',
        username => "44DD7C70Jre1dVgIsULcEyi+A+/cX9V5SAHkIiyVdWrHRG2tZm0rdintfZz85Pa/kGwq/1",
        password => "Abcd1234",
    );

CreateAccessCode

request AccessCode by submit customer/shippingaddress/payment/redirectUrl etc.

    ## Create AccessCode Request Object
    my $request = Business::eWAY::RapidAPI::CreateAccessCodeRequest->new();

    ## Populate values for Customer Object
    if (defined $q->param('txtTokenCustomerID')){
        $request->Customer->TokenCustomerID($q->param('txtTokenCustomerID'));
    };
    $request->Customer->Reference( $q->param('txtCustomerRef') );
    $request->Customer->Title( $q->param('ddlTitle') );
    # Note: FirstName is Required Field When Create/Update a TokenCustomer
    $request->Customer->FirstName( $q->param('txtFirstName') );
    # Note: LastName is Required Field When Create/Update a TokenCustomer
    $request->Customer->LastName( $q->param('txtLastName') );
    $request->Customer->CompanyName( $q->param('txtCompanyName') );
    $request->Customer->JobDescription( $q->param('txtJobDescription') );
    $request->Customer->Street1( $q->param('txtStreet1') );
    $request->Customer->Street2( $q->param('txtStreet2') );
    $request->Customer->City( $q->param('txtCity') );
    $request->Customer->State( $q->param('txtState') );
    $request->Customer->PostalCode( $q->param('txtPostalcode') );
    # Note: Country is Required Field When Create/Update a TokenCustomer
    $request->Customer->Country( $q->param('txtCountry') );
    $request->Customer->Email( $q->param('txtEmail') );
    $request->Customer->Phone( $q->param('txtPhone') );
    $request->Customer->Mobile( $q->param('txtMobile') );
    $request->Customer->Comments("Some Comments Here");
    $request->Customer->Fax("0131 208 0321");
    $request->Customer->Url("http://www.yoursite.com");

    ## Populate values for ShippingAddress Object.
    ## This values can be taken from a Form POST as well. Now is just some dummy data.
    $request->ShippingAddress->FirstName("John");
    $request->ShippingAddress->LastName("Doe");
    $request->ShippingAddress->Street1("9/10 St Andrew");
    $request->ShippingAddress->Street2(" Square");
    $request->ShippingAddress->City("Edinburgh");
    $request->ShippingAddress->State("");
    $request->ShippingAddress->Country("gb");
    $request->ShippingAddress->PostalCode("EH2 2AF");
    $request->ShippingAddress->Email('sales@eway.co.uk');
    $request->ShippingAddress->Phone("0131 208 0321");
    # ShippingMethod, e.g. "LowCost", "International", "Military". Check the spec for available values.
    $request->ShippingAddress->ShippingMethod("LowCost");

    ## Populate values for LineItems
    my $item1 = Business::eWAY::RapidAPI::LineItem->new();
    $item1->SKU("SKU1");
    $item1->Description("Description1");
    my $item2 = Business::eWAY::RapidAPI::LineItem->new();
    $item2->SKU("SKU2");
    $item2->Description("Description2");
    $request->Items->LineItem([ $item1, $item2 ]);

    ## Populate values for Options
    my $opt1 = Business::eWAY::RapidAPI::Option->new(Value => $q->param('txtOption1'));
    my $opt2 = Business::eWAY::RapidAPI::Option->new(Value => $q->param('txtOption2'));
    my $opt3 = Business::eWAY::RapidAPI::Option->new(Value => $q->param('txtOption3'));
    $request->Options->Option([$opt1, $opt2, $opt3]);

    $request->Payment->TotalAmount($q->param('txtAmount'));
    $request->Payment->InvoiceNumber($q->param('txtInvoiceNumber'));
    $request->Payment->InvoiceDescription( $q->param('txtInvoiceDescription') );
    $request->Payment->InvoiceReference( $q->param('txtInvoiceReference') );
    $request->Payment->CurrencyCode( $q->param('txtCurrencyCode') );

    ## Url to the page for getting the result with an AccessCode
    $request->RedirectUrl($q->param('txtRedirectURL'));
    ## Method for this request. e.g. ProcessPayment, Create TokenCustomer, Update TokenCustomer & TokenPayment
    $request->Method($q->param('ddlMethod'));

    my $result = $rapidapi->CreateAccessCode($request);

    ## Save result into Session. payment.pl and results.pl will retrieve this result from Session
    $session->param('TotalAmount', $q->param('txtAmount') );
    $session->param('InvoiceReference', $q->param('txtInvoiceReference') );
    $session->param('Response', $result );
    $session->flush();

    ## Check if any error returns
    if (defined( $result->{'Errors'} )) {
        $lblError = $rapidapi->ErrorsToString( $result->{'Errors'} );
    } else {
        ## All good then redirect to the payment page
        print $session->header(-location => 'payment.pl');
        exit();
    }

    ## $result is HASHREF contains
    ## FormActionURL
    ## AccessCode

GetAccessCodeResult

get payment result by previous stored AccessCode

    my $request = Business::eWAY::RapidAPI::GetAccessCodeResultRequest->new();
    $request->AccessCode($q->param('AccessCode'));

    ## Call RapidAPI to get the result
    my $result = $rapidapi->GetAccessCodeResult($request);

    ## Check if any error returns
    my $lblError;
    if (defined($result->{'Errors'})) {
        $lblError = $rapidapi->ErrorsToString($result->{'Errors'});
    }

    ## $result is HASHREF contains:
    ## ResponseCode
    ## Options
    ## TransactionID
    ## ... etc.

AUTHOR ^

Fayland Lam <fayland@gmail.com>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2014 by Fayland Lam.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: