Business-OnlinePayment-DLocal
view release on metacpan or search on metacpan
t/04-refund_status.t view on Meta::CPAN
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
use Test::More;
use Module::Runtime qw( use_module );
use Time::HiRes;
my $username = $ENV{PERL_BUSINESS_DLOCAL_USERNAME} || 'mocked';
my $password = $ENV{PERL_BUSINESS_DLOCAL_PASSWORD} || 'mocked';
my $secret = $ENV{PERL_BUSINESS_DLOCAL_SECRET} || 'mocked';
my $reports_username = $ENV{PERL_BUSINESS_DLOCAL_REPORTS_USERNAME} || 'mocked';
my $reports_key = $ENV{PERL_BUSINESS_DLOCAL_REPORTS_KEY} || 'mocked';
if ($username eq 'mocked') {
diag '';
diag '';
diag '';
diag 'All tests are run using MOCKED return values.';
diag 'If you wish to run REAL tests then add these ENV variables.';
diag '';
diag 'export PERL_BUSINESS_DLOCAL_USERNAME=your_test_user';
diag 'export PERL_BUSINESS_DLOCAL_PASSWORD=your_test_password';
diag 'export PERL_BUSINESS_DLOCAL_SECRET=your_test_secret';
diag 'export PERL_BUSINESS_DLOCAL_REPORTS_USERNAME=your_reports_user';
diag 'export PERL_BUSINESS_DLOCAL_REPORTS_KEY=your_reports_key';
diag '';
diag '';
}
if ( $username ne 'mocked' && $password ne 'mocked') {
plan tests => 6;
} else {
plan skip_all => 'No credentials set in the environment.'
. ' Set PERL_BUSINESS_DLOCAL_USERNAME and '
. ' PERL_BUSINESS_DLOCAL_SECRET and '
. 'PERL_BUSINESS_DLOCAL_PASSWORD to run this test.'
}
my $client = new_ok( use_module('Business::OnlinePayment'), ['DLocal'] );
$client->test_transaction(1); # test, dont really charge
my $data = {
login => $username,
password => $password,
password2 => $secret,
reports_login => $reports_username,
reports_key => $reports_key,
##### action => 'fetchByMerchantTransactionId',
description => 'Business::OnlinePayment visa test',
division_number => '1',
type => 'CC',
amount => '90.00',
customer_number => '123',
subscription_number => 'TEST-'.Time::HiRes::time(),
invoice_number => 'TEST-'.Time::HiRes::time(),
authorization => '123456',
timestamp => '2012-09-11T22:34:32.265Z',
first_name => 'Tofu',
last_name => 'Beast',
address => '123 Anystreet',
city => 'Anywhere',
state => 'UT',
zip => '84058',
country => 'BR',
currency => 'USD',
email => 'bop@example.com',
card_number => '4556993263529121',
cvv2 => '554',
cpf => '00003456789',
expiration => '06/19',
vindicia_nvp => {
custom_test => 'BOP:DLocal unit test',
}
};
SKIP: { # Save
subtest 'Tokenize' => sub {
plan tests => 2;
local $data->{'action'} = 'Tokenize';
$client->content(%$data);
push @{$client->{'mocked'}}, {
action => 'tokenize',
login => 'mocked',
resp => '{"status":"OK","desc":"authorized","control":"C265401C3B048F429B7523692F0551CD2E7C4E2109680B86BE598E11C5D7B979","cc_token":"1efcd735c820a542e0e0de57b7900d4b"}',
} if $data->{'login'} eq 'mocked';
my $ret = $client->submit();
ok($client->is_success, 'Transaction is_success');
ok($client->card_token, 'Transaction card_token found');
} or diag explain "Request:\n".$client->server_request,"\nResponse:\n".$client->server_response;
$data->{'card_token'} = $client->card_token; # all tests below will use this
}
SKIP: { # Sale with token
( run in 0.995 second using v1.01-cache-2.11-cpan-97f6503c9c8 )