Business-GoCardless

 view release on metacpan or  search on metacpan

lib/Business/GoCardless/Client.pm  view on Meta::CPAN

        Business::GoCardless::Exception->throw({
            message => "Invalid signature for confirm_resource"
        });
    }

    my $data = {
        resource_id   => $params->{resource_id},
        resource_type => $params->{resource_type},
    };

    my $credentials = encode_base64( $self->app_id . ':' . $self->app_secret );
    $credentials    =~ s/\s//g;

    my $ua = LWP::UserAgent->new;
    $ua->agent( $self->user_agent );

    my $req = HTTP::Request->new(
        POST => join( '/',$self->base_url . $self->api_path,'confirm' )
    );

    $req->header( 'Authorization' => "Basic $credentials" );
    $req->header( 'Accept' => 'application/json' );

    $req->content_type( 'application/x-www-form-urlencoded' );
    $req->content( $self->normalize_params( $data ) );

    my $res = $ua->request( $req );

    if ( $res->is_success ) {
        
        my $class_suffix = ucfirst( $params->{resource_type} );

t/business/gocardless.t  view on Meta::CPAN

);

cmp_deeply(
    $GoCardless->client_details,
    { api_version => 1 },
    'client_details'
);
isa_ok( $GoCardless->client,'Business::GoCardless::Client' );

# monkey patching LWP here to make this test work without
# having to actually hit the endpoints or use credentials
no warnings 'redefine';
no warnings 'once';
my $mock = Test::MockObject->new;
$mock->mock( 'is_success',sub { 1 } );
$mock->mock( 'header',sub {} );
*LWP::UserAgent::request = sub { $mock };

test_bill( $GoCardless,$mock );
test_merchant( $GoCardless,$mock );
test_payout( $GoCardless,$mock );

t/business/gocardless/billingrequest.t  view on Meta::CPAN

is( $BillingRequest->mandate_id,'MD123','->mandate_id' );
is( $BillingRequest->payment_id,'PM123','->payment_id' );
is( $BillingRequest->subscription_id,'SB123','->subscription_id' );

$BillingRequest->links( undef );
ok( ! $BillingRequest->customer_id,'! ->customer_id when no links' );

note( "operations" );

# monkey patching LWP here to make this test work without
# having to actually hit the endpoints or use credentials
no warnings 'redefine';
no warnings 'once';
my $mock = Test::MockObject->new;
my $request;
$mock->mock( 'is_success',sub { 1 } );
$mock->mock( 'header',sub {} );
*LWP::UserAgent::request = sub { $request = $_[1]; $mock };

$mock->mock( 'content',sub { '{"billing_requests":{"id":"BRQ123","status":"after collect_customer_details"}}' } );

t/business/gocardless/billingrequestflow.t  view on Meta::CPAN

        initialise
    /,
);

is( $Flow->endpoint,'/billing_request_flows/%s','endpoint' );
is( $Flow->uri,'https://api.gocardless.com/billing_request_flows/ID123','->uri' );

note( "operations" );

# monkey patching LWP here to make this test work without
# having to actually hit the endpoints or use credentials
no warnings 'redefine';
no warnings 'once';
my $mock = Test::MockObject->new;
my $request;
$mock->mock( 'is_success',sub { 1 } );
$mock->mock( 'header',sub {} );
*LWP::UserAgent::request = sub { $request = $_[1]; $mock };

$mock->mock( 'content',sub { '{"billing_request_flows":{"id":"ID123","session_token":"after initialise"}}' } );

t/business/gocardless/billingrequesttemplate.t  view on Meta::CPAN

        update
    /,
);

is( $Template->endpoint,'/billing_request_templates/%s','endpoint' );
is( $Template->uri,'https://api.gocardless.com/billing_request_templates/ID123','->uri' );

note( "operations" );

# monkey patching LWP here to make this test work without
# having to actually hit the endpoints or use credentials
no warnings 'redefine';
no warnings 'once';
my $mock = Test::MockObject->new;
my $request;
$mock->mock( 'is_success',sub { 1 } );
$mock->mock( 'header',sub {} );
*LWP::UserAgent::request = sub { $request = $_[1]; $mock };

$mock->mock( 'content',sub { '{"billing_request_templates":{"id":"ID123","name":"after update"}}' } );

t/business/gocardless/block.t  view on Meta::CPAN

        enable
    /,
);

is( $Block->endpoint,'/blocks/%s','endpoint' );
is( $Block->uri,'https://api.gocardless.com/blocks/ID123','->uri' );

note( "operations" );

# monkey patching LWP here to make this test work without
# having to actually hit the endpoints or use credentials
no warnings 'redefine';
no warnings 'once';
my $mock = Test::MockObject->new;
my $request;
$mock->mock( 'is_success',sub { 1 } );
$mock->mock( 'header',sub {} );
*LWP::UserAgent::request = sub { $request = $_[1]; $mock };

$mock->mock( 'content',sub { '{"blocks":{"id":"ID123","active":"after disable"}}' } );

t/business/gocardless/creditor.t  view on Meta::CPAN

        update
    /,
);

is( $Creditor->endpoint,'/creditors/%s','endpoint' );
is( $Creditor->uri,'https://api.gocardless.com/creditors/ID123','->uri' );

note( "operations" );

# monkey patching LWP here to make this test work without
# having to actually hit the endpoints or use credentials
no warnings 'redefine';
no warnings 'once';
my $mock = Test::MockObject->new;
my $request;
$mock->mock( 'is_success',sub { 1 } );
$mock->mock( 'header',sub {} );
*LWP::UserAgent::request = sub { $request = $_[1]; $mock };

$mock->mock( 'content',sub { '{"creditors":{"id":"ID123","name":"after update"}}' } );

t/business/gocardless/creditorbankaccount.t  view on Meta::CPAN

note( "links" );

is( $BankAccount->creditor_id,'CR123','->creditor_id' );

$BankAccount->links( undef );
ok( ! $BankAccount->creditor_id,'! ->creditor_id when no links' );

note( "operations" );

# monkey patching LWP here to make this test work without
# having to actually hit the endpoints or use credentials
no warnings 'redefine';
no warnings 'once';
my $mock = Test::MockObject->new;
my $request;
$mock->mock( 'is_success',sub { 1 } );
$mock->mock( 'header',sub {} );
*LWP::UserAgent::request = sub { $request = $_[1]; $mock };

$mock->mock( 'content',sub { '{"creditor_bank_accounts":{"id":"ID123","enabled":"after disable"}}' } );

t/business/gocardless/customerbankaccount.t  view on Meta::CPAN

note( "links" );

is( $BankAccount->customer_id,'CU123','->customer_id' );

$BankAccount->links( undef );
ok( ! $BankAccount->customer_id,'! ->customer_id when no links' );

note( "operations" );

# monkey patching LWP here to make this test work without
# having to actually hit the endpoints or use credentials
no warnings 'redefine';
no warnings 'once';
my $mock = Test::MockObject->new;
my $request;
$mock->mock( 'is_success',sub { 1 } );
$mock->mock( 'header',sub {} );
*LWP::UserAgent::request = sub { $request = $_[1]; $mock };

$mock->mock( 'content',sub { '{"customer_bank_accounts":{"id":"ID123","enabled":"after update"}}' } );

t/business/gocardless/customernotification.t  view on Meta::CPAN

        handle
    /,
);

is( $Notification->endpoint,'/customer_notifications/%s','endpoint' );
is( $Notification->uri,'https://api.gocardless.com/customer_notifications/ID123','->uri' );

note( "operations" );

# monkey patching LWP here to make this test work without
# having to actually hit the endpoints or use credentials
no warnings 'redefine';
no warnings 'once';
my $mock = Test::MockObject->new;
my $request;
$mock->mock( 'is_success',sub { 1 } );
$mock->mock( 'header',sub {} );
*LWP::UserAgent::request = sub { $request = $_[1]; $mock };

$mock->mock( 'content',sub { '{"customer_notifications":{"id":"ID123","action_taken":"after handle"}}' } );

t/business/gocardless/instalmentschedule.t  view on Meta::CPAN


is( $Schedule->customer_id,'CU123','->customer_id' );
is( $Schedule->mandate_id,'MD123','->mandate_id' );

$Schedule->links( undef );
ok( ! $Schedule->customer_id,'! ->customer_id when no links' );

note( "operations" );

# monkey patching LWP here to make this test work without
# having to actually hit the endpoints or use credentials
no warnings 'redefine';
no warnings 'once';
my $mock = Test::MockObject->new;
my $request;
$mock->mock( 'is_success',sub { 1 } );
$mock->mock( 'header',sub {} );
*LWP::UserAgent::request = sub { $request = $_[1]; $mock };

$mock->mock( 'content',sub { '{"instalment_schedules":{"id":"ID123","status":"after update"}}' } );

t/business/gocardless/mandate.t  view on Meta::CPAN

ok( ! $Mandate->is_vrp_sweeping,'! ->is_vrp_sweeping' );

$Mandate->mandate_type( 'instant' );
ok( ! $Mandate->is_bank_debit,'! ->is_bank_debit after change' );
ok( $Mandate->is_instant,'->is_instant after change' );

$Mandate->id( 123 );
is( $Mandate->uri,'https://api.gocardless.com/mandates/123','->uri' );

# monkey patching LWP here to make this test work without
# having to actually hit the endpoints or use credentials
no warnings 'redefine';
no warnings 'once';
my $mock = Test::MockObject->new;
my $request;
$mock->mock( 'is_success',sub { 1 } );
$mock->mock( 'header',sub {} );
$mock->mock( 'content',sub {
    '{"mandates":{"id":"123","status":"active","metadata":{"contract":"ABC"}}}'
} );
*LWP::UserAgent::request = sub { $request = $_[1]; $mock };

t/business/gocardless/mandateimport.t  view on Meta::CPAN

foreach my $status ( @statuses ) {
    $Import->status( $status );
    ok( $Import->$status,"->$status" );
    ok( ! $Import->$_,"! ->$_ when $status" )
        for grep { $_ ne $status } @statuses;
}

note( "operations" );

# monkey patching LWP here to make this test work without
# having to actually hit the endpoints or use credentials
no warnings 'redefine';
no warnings 'once';
my $mock = Test::MockObject->new;
my $request;
$mock->mock( 'is_success',sub { 1 } );
$mock->mock( 'header',sub {} );
*LWP::UserAgent::request = sub { $request = $_[1]; $mock };

$mock->mock( 'content',sub { '{"mandate_imports":{"id":"ID123","status":"after submit"}}' } );

t/business/gocardless/outboundpayment.t  view on Meta::CPAN

foreach my $status ( @statuses ) {
    $OutboundPayment->status( $status );
    ok( $OutboundPayment->$status,"->$status" );
    ok( ! $OutboundPayment->$_,"! ->$_ when $status" )
        for grep { $_ ne $status } @statuses;
}

note( "operations" );

# monkey patching LWP here to make this test work without
# having to actually hit the endpoints or use credentials
no warnings 'redefine';
no warnings 'once';
my $mock = Test::MockObject->new;
my $request;
$mock->mock( 'is_success',sub { 1 } );
$mock->mock( 'header',sub {} );
*LWP::UserAgent::request = sub { $request = $_[1]; $mock };

$mock->mock( 'content',sub { '{"outbound_payments":{"id":"ID123","status":"after update"}}' } );

t/business/gocardless/paginator.t  view on Meta::CPAN

            'last' => 2,
            'next' => 2,
        },
        'pages' => 2,
        'records' => 15,
    },
    'info'
);

# monkey patching LWP here to make this test work without
# having to actually hit the endpoints or use credentials
no warnings 'redefine';
no warnings 'once';
my $mock = Test::MockObject->new;
$mock->mock( 'is_success',sub { 1 } );
$mock->mock( 'header',sub {
    my ( $self,$want ) = @_;
    return {
        'link'         => $link,
        'x-pagination' => '{"records":15,"pages":2,"links":{"next":2,"last":2}}}'
    }->{ lc( $want ) };

t/business/gocardless/pro.t  view on Meta::CPAN

);

cmp_deeply(
    $GoCardless->client_details,
    { api_version => 2 },
    'client_details'
);
isa_ok( $GoCardless->client,'Business::GoCardless::Client' );

# monkey patching LWP here to make this test work without
# having to actually hit the endpoints or use credentials
no warnings 'redefine';
no warnings 'once';
my $mock = Test::MockObject->new;
$mock->mock( 'is_success',sub { 1 } );
$mock->mock( 'header',sub {} );
# the fixtures in this test are character strings, but a real response is
# UTF-8 encoded bytes, so encode the content as LWP would give it to us
my $response = Test::MockObject->new;
$response->mock( q{is_success},sub { $mock->is_success } );
$response->mock( q{header},sub { shift; $mock->header( @_ ) } );

t/business/gocardless/redirectflow.t  view on Meta::CPAN

ok( ! $RedirectFlow->cancelled,'cancelled' );
ok( ! $RedirectFlow->expired,'expired' );

throws_ok(
    sub { $RedirectFlow->cancel },
    'Business::GoCardless::Exception',
    "->cancel on a RedirectFlow is not meaningful in the Pro API",
);

# monkey patching LWP here to make this test work without
# having to actually hit the endpoints or use credentials
no warnings 'redefine';
no warnings 'once';
my $mock = Test::MockObject->new;
$mock->mock( 'is_success',sub { 1 } );
$mock->mock( 'header',sub {} );
*LWP::UserAgent::request = sub { $mock };
my $i = 0;
$mock->mock( 'content',sub { ! $i++ ? _redirect_flow_json() : _mandate_json() } );

is( $RedirectFlow->mandate->next_possible_charge_date,'2017-09-27','->mandate' );



( run in 1.294 second using v1.01-cache-2.11-cpan-3f962061493 )