Business-GoCardless
view release on metacpan or search on metacpan
t/004_end_to_end_pro.t view on Meta::CPAN
#!perl
use strict;
use warnings;
use utf8;
use Test::Most;
use Test::Deep;
use Test::Exception;
use LWP::Simple;
use Business::GoCardless::Pro;
use JSON qw/ decode_json /;
use POSIX qw/ strftime /;
use FindBin qw/ $Bin /;
my $tmp_dir = "$Bin/end_to_end";
plan skip_all => "GOCARDLESS_ENDTOEND required"
if ! $ENV{GOCARDLESS_ENDTOEND};
eval 'use Mojo::UserAgent';
$@ && plan skip_all => "Install Mojolicious to run this test";
# this is an "end to end" test - it will call the gocardless API
# using the details defined in the ENV variables below. you need
# to run t/gocardless_callback_reader.pl allowing the callbacks
# from gocardless to succeed, which feeds the details back into
# this script (hence "end to end") - note that the redirect URI
# and webhook URI in the sandbox/live developer settings will also
# need to match that of the address running the script
my ( $token,$url,$DEBUG ) = @ENV{qw/
GOCARDLESS_TOKEN
GOCARDLESS_URL
GOCARDLESS_DEBUG
/};
# this makes Business::GoCardless::Exception show a stack
# trace when any error is thrown so i don't have to keep
# wrapping stuff in this test in evals to debug
$ENV{GOCARDLESS_DEV_TESTING} = 1;
my $GoCardless = Business::GoCardless::Pro->new(
token => $token,
# since these are set in %ENV we don't need to pass them
# but am showing them being passed here for example usage
client_details => {
base_url => $url,
},
);
isa_ok( $GoCardless,'Business::GoCardless::Pro' );
my $new_url = $GoCardless->new_bill_url(
session_token => 'foo',
description => "Test Bill",
# not sure about having the amount + currency in the redirect URL (what's
# to stop user from changing it?) but can't see any other way to be back
# compat with the Basic API
success_redirect_url => "http://localhost:3000/rflow/confirm/bill/100/GBP",
);
_post_to_gocardless( $new_url,'bill' );
my $confirm_resource_data = _get_confirm_resource_data( "$tmp_dir/redirect_flow.json" );
note explain $confirm_resource_data if $DEBUG;
isa_ok(
my $Bill = $GoCardless->confirm_resource( %{ $confirm_resource_data } ),
'Business::GoCardless::Payment'
);
ok( $Bill->cancel,'cancel bill' );
ok( $Bill->cancelled,'bill cancelled' );
my $NewBill = $GoCardless->bill( $Bill->id );
is( $NewBill->id,$Bill->id,'getting bill with same id gives same bill' );
my $Paginator = $GoCardless->bills(
limit => 500,
);
note explain $Paginator->info if $DEBUG;
while ( my @bills = $Paginator->next ) {
pass( 'Paginator->next' );
if ( $DEBUG ) {
( run in 1.988 second using v1.01-cache-2.11-cpan-97f6503c9c8 )