NAME
Business::PinPayment - Interface for Pin Payment API
SYNOPSIS
use Business::PinPayment;
# Run a test charge of $1.00
my $test = Business::PinPayment->new(config => {api_key => 'T3sTS3cret-ap1key'});
if ($test->successful()) {
print 'Test Successful';
}
else {
print $test->error();
}
# Run a live one
my $live = Business::PinPayment->new(
live => 1,
config => {
api_key => 'L1veS3cret-ap1key',
amount => '100',
currency => 'AUD',
description => 'charges',
email => 'tester@work.com.au',
card => {
number => '5520000000000000',
expiry_month => '05',
expiry_year => '2014',
cvc => '123',
name => 'John Smith',
address_line1 => '1 Test St',
address_city => 'Sydney',
address_postcode => '2000',
address_state => 'NSW',
address_country => 'Australia'
}
}
);
DESCRIPTION
An interface to the Pin Payment API.
METHODS
new
Instantiates a new PinPayment object. By default, it runs a test transaction with the given API key.
config
-
A hashref of parameters accepted by the PinPayment API . See https://pin.net.au/docs/api. Default values:
api_version => '1', # the '1' in the API endpoint host names, e.g. https://test-api.pin.net.au/1/charges api_key => undef, # Secret API Key api => 'charges', # 'customers', 'refunds' amount => '100', # 100 cents. Must be greater or equal to $1.00 currency => 'AUD', # 'USD', 'NZD', or 'SGD' description => 'charges', email => 'tester@work.com.au', ip_address => undef, charge_token => undef, # for refunds API card_token => undef, customer_token => undef, card => { number => '5520000000000000', expiry_month => '05', expiry_year => '2014', cvc => '123', name => 'John Smith', address_line1 => '1 Test St', address_line2 => undef, address_city => 'Sydney', address_postcode => '2000', address_state => 'NSW', address_country => 'Australia', }
The following script performs a test charge and then refunds it. It then creates a test customer, charges the created customer via the customer token (ID) and card token.
# You may need to disable SSL host name verification for testing $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; my $test_api_key = 'L1veS3cret-ap1key'; # Test charge for $1.00 my $charge = Business::PinPayment->new( config => { api_key => $test_api_key, card => { number => '5520000000000000', expiry_month => '05', expiry_year => '2014', cvc => '123', name => 'John Smith', address_line1 => '1 Test St', address_city => 'Sydney', address_postcode => '2000', address_state => 'NSW', address_country => 'Australia' } } ); if ($charge->successful()) { print 'Charge Token: ' . $charge->id() . "\n"; # Refund the charge my $refund = Business::PinPayment->new( config => { api => 'refunds', api_key => $test_api_key, charge_token => $charge->id() } ); if ($refund->successful()) { print 'Refund Token: ' . $refund->id() . "\n"; } else { print 'Refund Error: ' . $refund->error() . "\n"; } } else { print 'Charge Error: ' . $charge->error() . "\n"; } # Create a customer my $customer = Business::PinPayment->new( config => { api => 'customers', api_key => $test_api_key, card => { number => '5520000000000000', expiry_month => '05', expiry_year => '2014', cvc => '123', name => 'John Smith', address_line1 => '1 Test St', address_city => 'Sydney', address_postcode => '2000', address_state => 'NSW', address_country => 'Australia' } } ); if ($customer->successful()) { print 'Customer Token: ' . $customer->id() . "\n"; # Charge the customer $1.00 my $charge_customer = Business::PinPayment->new( config => { api => 'charges', api_key => $test_api_key, customer_token => $customer->id() }, ); if ($charge_customer->successful()) { print 'Charge Customer Token: ' . $charge_customer->id() . "\n"; } else { print 'Charge Customer Error: ' . $charge_customer->error() . "\n"; } # Charge the customer's card token $1.00 my $charge_card = Business::PinPayment->new( config => { api => 'charges', api_key => $test_api_key, card_token => $customer->card_token(), }, ); if ($charge_card->successful()) { print 'Charge Card Token: ' . $charge_card->id() . "\n"; } else { print 'Charge Card Error: ' . $charge_card->error() . "\n"; } } else { print 'Customer Error: ' . $charge->error() . "\n"; }
live
-
Use the live URL when set to 1.
successful
Returns true if the transaction is successful.
error
Returns the error message.
response
Returns the response of the HTTP::Request object.
json_response
Returns a hashref of the JSON response content.
id
Returns the transaction 'token'.
status
Returns the successful 'status_message', error message or code.
card_token
Returns the 'card_token'.
SEE ALSO
HTTP::Request, LWP::UserAgent, https://pin.net.au
AUTHOR
Xufeng (Danny) Liang (danny.glue@gmail.com)
COPYRIGHT & LICENSE
Copyright 2013 Xufeng (Danny) Liang, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.