Business-GoCardless

 view release on metacpan or  search on metacpan

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

    %params = ( metadata => { ... } );

=cut

sub cancel { shift->_operation( undef,'api_post',undef,'actions/cancel' ); }

sub update {
    my ( $self,%params ) = @_;

    return $self->client->api_put(
        sprintf( $self->endpoint,$self->id ),
        { mandates => { %params } },
    );
}

=head1 Status checks on a mandate

    pending_customer_approval
    pending_submission
    submitted
    active

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

    pending_balance
    sub_resource_uris
    uri
/ ] => (
    is => 'rw',
);

sub BUILD {
    my ( $self ) = @_;

    my $data = $self->client->api_get( sprintf( $self->endpoint,$self->id ) );

    foreach my $attr ( keys( %{ $data } ) ) {
        eval { $self->$attr( $data->{$attr} ); };
        $@ && do {
            carp( "Couldn't set $attr on @{[ ref( $self ) ]}: $@" );
        };
    }

    return $self;
}

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


=cut

sub bills              { shift->_list( 'bills',shift ) }
sub pre_authorizations { shift->_list( 'pre_authorizations',shift )}
sub subscriptions      { shift->_list( 'subscriptions',shift ) }
sub payouts            { shift->_list( 'payouts',shift ) }
sub users              { shift->_list( 'users',shift ) }

sub _list {
    my ( $self,$endpoint,$filters ) = @_;

    my $class = {
        bills              => 'Bill',
        pre_authorizations => 'PreAuthorization',
        subscriptions      => 'Subscription',
        payouts            => 'Payout',
        users              => 'User',
    }->{ $endpoint };

    $filters             //= {};
    $filters->{per_page} ||= 100;
    $filters->{page}     ||= 1;

    my $uri = sprintf( $self->endpoint,$self->id ) . "/$endpoint";

    if ( keys( %{ $filters } ) ) {
        $uri .= '?' . $self->client->normalize_params( $filters );
    }

    my ( $data,$links,$info ) = $self->client->api_get( $uri );

    $class = "Business::GoCardless::$class";
    my @objects = map { $class->new( client => $self->client,%{ $_ } ) }
        @{ $data };

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

    cancel
    refund

    $Payment->retry if $Payment->failed;

=cut

sub retry  { shift->_operation( undef,'api_post',undef,'actions/retry' ); }
sub cancel { shift->_operation( undef,'api_post',undef,'actions/cancel' ); }
sub refund {
    # apparently this endpoint is restricted by default, so nuts to it for now
    return 0;
}

=head1 Status checks on a payment

    pending
    paid
    failed
    chargedback
    cancelled

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

API methods will be added at a later stage (also: patches welcome).

Also note this class also currently inherits from L<Business::GoCardless>
so has all attributes and methods available on that class (some of which may not
make sense from the context of the Pro API).

=head1 SYNOPSIS

The following examples show instantiating the object and getting a resource
(Payment in this case) to manipulate. For more examples see the t/004_end_to_end_pro.t
script, which can be run against the gocardless sandbox (or even live) endpoint
when given the necessary ENV variables.

    my $GoCardless = Business::GoCardless::Pro->new(
        token           => $your_gocardless_token
        client_details  => {
            base_url       => $gocardless_url, # defaults to https://api.gocardless.com
            webhook_secret => $secret,
        },
    );

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


=head2 payout

Get an individual payout, returns a L<Business::GoCardless::Payout> object:

    my $Payout = $GoCardless->payout( $id );

=cut

sub _list {
    my ( $self,$endpoint,$filters ) = @_;

    my $class = {
        payments       => 'Payment',
        redirect_flows => 'RedirectFlow',
        customers      => 'Customer',
        subscriptions  => 'Subscription',
        webhooks       => 'Webhook::V2',
        payouts        => 'Payout',
    }->{ $endpoint };

    $filters //= {};

    my $uri = "/$endpoint";

    if ( keys( %{ $filters } ) ) {
        $uri .= '?' . $self->client->normalize_params( $filters );
    }

    my ( $data,$links,$info ) = $self->client->api_get( $uri );

    $class = "Business::GoCardless::$class";
    my @objects = map { $class->new(
        client => $self->client,

        # webhooks come back with stringified JSON
        # so we need to further decode that
        $endpoint eq 'webhooks'
            ? (
                json => $_->{request_body},
                # load ordering handled by setting _signature rather than signature
                # signature will be set in the json trigger
                _signature => $_->{request_headers}{'Webhook-Signature'}
            )
            : ( %{ $_ } )
    ); } @{ $data->{$endpoint} };

    return wantarray ? ( @objects ) : Business::GoCardless::Paginator->new(
        class   => $class,
        client  => $self->client,
        links   => $links,
        info    => $info ? JSON->new->decode( $info ) : {},
        objects => \@objects,
    );
}

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


use strict;
use warnings;

use Moo;
use Carp qw/ carp confess /;
use JSON ();

=head1 ATTRIBUTES

=head2 endpoint

The gocardless API endpoint that corresponds to the resource, for example a
L<Business::GoCardless::Bill> object will have an endpoint of "bills". This
is handled automatically, you do not need to pass this unless the name of the
resource differs significantly from the endpoint.

=head2 client

The client object, defaults to L<Business::GoCardless::Client>.

=cut

has endpoint => (
    is       => 'ro',
    default  => sub {
        my ( $self ) = @_;
        my ( $class ) = ( split( ':',ref( $self ) ) )[-1];

        confess( "You must subclass Business::GoCardless::Resource" )
            if $class eq 'Resource';

        $class =~ s/([a-z])([A-Z])/$1 . '_' . lc( $2 )/eg;
        $class = lc( $class );

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

Calls the gocardless API and populates the resource object with the data.

    my $Bill = Business::GoCardless::Bill->new( client => $self->client );
    $Bill->find_with_client;

=cut

sub find_with_client {
    my ( $self,$sub_key ) = @_;

    my $path = sprintf( $self->endpoint,( $self->id // '' ) );
    my $data = $self->client->api_get( $path );

    $data = $data->{$sub_key} if $sub_key;

    foreach my $attr ( keys( %{ $data } ) ) {
        # as per https://developer.gocardless.com/api-reference/#overview-backwards-compatibility
        #
        #     The following changes are considered backwards compatible
        #     "Adding new properties to the responses from existing API endpoints"
        #
        # so we need to be able to handle attributes we don't know about yet, hence the eval
        eval { $self->$attr( $data->{$attr} ); };
        $@ && do {
            carp( "Couldn't set $attr on @{[ ref( $self ) ]}: $@" );
        };
    }

    return $self;
}

sub _operation {
    my ( $self,$operation,$method,$params,$suffix ) = @_;

    $method //= 'api_post',

    my $uri = $operation
        ? sprintf( $self->endpoint,$self->id ) . "/$operation"
        : sprintf( $self->endpoint,$self->id );

    $uri .= "/$suffix" if $suffix;

    my $data = $self->client->$method( $uri,$params );

    if ( $self->client->api_version > 1 ) {

        $data = $data->{payments}
            if ref( $self ) eq 'Business::GoCardless::Payment';
        $data = $data->{subscriptions}

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

            carp( "Couldn't set $attr on @{[ ref( $self ) ]}: $@" );
        };
    }

    return $self;
}

sub uri {
    my ( $self ) = @_;

    my $endpoint = sprintf( $self->endpoint,$self->id );

    return $self->client->api_version > 1
        ? join( '/',$self->client->base_url . $self->client->api_path . $endpoint )
        : join( '/',$self->client->base_url . $endpoint );
}

=head2 to_hash

Returns a hash representation of the object.

    my %data = $Bill->to_hash;

=head2 to_json

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.t  view on Meta::CPAN

  } }

}

sub _user_obj {

    return bless( {
   'client' => ignore(),
   'created_at' => '2011-11-18T17:06:15Z',
   'email' => 'customer40@gocardless.com',
   'endpoint' => '/users/%s',
   'first_name' => 'Frank',
   'id' => 'JKH8HGKL9H',
   'last_name' => 'Smith'
 }, 'Business::GoCardless::User' );

}

sub _subscription_json {

    my ( $status ) = @_;

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

    my ( $status ) = @_;

    $status //= 'active';

    return bless( {
   'amount' => '7.50',
   'client' => ignore(),
   'created_at' => '2014-08-20T21:41:25Z',
   'currency' => 'GBP',
   'description' => 'GoCardless magazine',
   'endpoint' => '/subscriptions/%s',
   'expires_at' => '2016-08-20T21:41:25Z',
   'id' => '0NZ71WBMVF',
   'interval_length' => '1',
   'interval_unit' => 'month',
   'merchant_id' => '06Z06JWQW1',
   'name' => 'Membership subscription',
   'next_interval_start' => '2014-09-20T00:00:00Z',
   'setup_fee' => '0.00',
   'start_at' => '2014-12-31T00:00:00Z',
   'status' => $status,

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


    my ( $status ) = @_;

    $status //= 'active';

    return bless( {
  'client' => ignore(),
  'created_at' => '2014-08-20T21:41:25Z',
  'currency' => 'GBP',
  'description' => 'GoCardless magazine',
  'endpoint' => '/pre_authorizations/%s',
  'expires_at' => '2016-08-20T21:41:25Z',
  'id' => '1234ABCD',
  'interval_length' => '1',
  'interval_unit' => 'month',
  'max_amount' => '750.00',
  'merchant_id' => '06Z06JWQW1',
  'name' => 'Computer support invoices',
  'next_interval_start' => '2014-09-20T00:00:00Z',
  'remaining_amount' => '750.00',
  'setup_fee' => '10.00',

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

    my ( $extra ) = @_;

    $extra //= {};

    return bless( {
     %{ $extra },
     'amount' => '12.37',
     'bank_reference' => 'JOHNSMITH-Z5DRM',
     'client' => ignore(),
     'created_at' => '2013-05-10T16:34:34Z',
     'endpoint' => '/payouts/%s',
     'id' => '0BKR1AZNJF',
     'paid_at' => '2013-05-10T17:00:26Z',
     'transaction_fees' => '0.13'
   }, 'Business::GoCardless::Payout' );
}

sub _merchant_json {

    return qq{{
  "id":"06Z06JWQW1",

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


sub _merchant_obj {

    return bless(
        {
            'balance' => '0.0',
            'client' => ignore(),
            'created_at'           => '2014-01-22T10:27:42Z',
            'description'          => 'We do stuff.',
            'email'                => 'lee@foo.com',
            'endpoint'             => '/merchants/%s',
            'eur_balance'          => '0.0',
            'eur_pending_balance'  => '0.0',
            'first_name'           => 'Lee',
            'gbp_balance'          => '0.0',
            'gbp_pending_balance'  => '0.0',
            'hide_variable_amount' => JSON::false,
            'id'                   => '06Z06JWQW1',
            'last_name'            => 'Johnson',
            'name'                 => 'Company Ltd',
            'next_payout_amount'   => undef,

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

    $status //= 'pending';

    return bless({
        'amount'             => '44.0',
        'can_be_retried'     => JSON::false,
        'charge_customer_at' => '2014-09-01',
        'client' => ignore(),
        'created_at'      => '2014-08-20T21:41:25Z',
        'currency'        => 'GBP',
        'description'     => 'Month 2 payment',
        'endpoint'        => '/bills/%s',
        'gocardless_fees' => '0.44',
        'id'              => '123ABCD',
        'is_setup_fee'    => JSON::false,
        'merchant_id'     => '06Z06JWQW1',
        'name'            => 'Bill 2 for Subscription description',
        'paid_at'         => undef,
        'partner_fees'    => '0',
        'payout_id'       => undef,
        'source_id'       => 'YH1VEVQHYVB1UT',
        'source_type'     => 'ad_hoc_authorization',

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

            app_secret  => 'baz',
            merchant_id => 'boz',
        ),
    ),
    'Business::GoCardless::Bill'
);

can_ok(
    $Bill,
    qw/
        endpoint
        amount
        gocardless_fees
        partner_fees
        amount_minus_fees
        currency
        description
        name
        status
        can_be_retried
        can_be_cancelled

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

        pending
        paid
        failed
        chargedback
        cancelled
        withdrawn
        refunded
    /,
);

is( $Bill->endpoint,'/bills/%s','endpoint' );

$Bill->status( 'unknown' );

ok( ! $Bill->pending,'pending' );
ok( ! $Bill->paid,'paid' );
ok( ! $Bill->failed,'failed' );
ok( ! $Bill->chargedback,'chargedback' );
ok( ! $Bill->cancelled,'cancelled' );
ok( ! $Bill->withdrawn,'withdrawn' );
ok( ! $Bill->refunded,'refunded' );

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

    $Customer,
    qw/
        created_at
        email
        first_name
        id
        last_name
    /,
);

is( $Customer->endpoint,'/customers/%s','endpoint' );
is( $Customer->first_name,$Customer->given_name,'->first_name' );
is( $Customer->last_name,$Customer->family_name,'->last_name' );

done_testing();

# vim: ts=4:sw=4:et

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

		metadata
		next_possible_charge_date
		payments_require_approval
		reference
		scheme
		status
        verified_at
    /,
);

is( $Mandate->endpoint,'/mandates/%s','endpoint' );
$Mandate->status( 'active' );

ok( ! $Mandate->pending_customer_approval,'pending_customer_approval' );
ok( ! $Mandate->pending_submission,'pending_submission' );
ok( ! $Mandate->submitted,'submitted' );
ok( $Mandate->active,'active' );
ok( ! $Mandate->failed,'failed' );
ok( ! $Mandate->cancelled,'cancelled' );
ok( ! $Mandate->expired,'expired' );
ok( ! $Mandate->consent_parameters,'consent_parameters' );

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

            app_secret  => 'baz',
            merchant_id => 'boz',
        ),
    ),
    'Business::GoCardless::Merchant'
);

can_ok(
    $Merchant,
    qw/
        endpoint
        balance
        created_at
        description
        email
        eur_balance
        eur_pending_balance
        first_name
        gbp_balance
        gbp_pending_balance
        hide_variable_amount

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

        last_name
        name
        next_payout_amount
        next_payout_date
        pending_balance
        sub_resource_uris
        uri
    /,
);

is( $Merchant->endpoint,'/merchants/%s','endpoint' );

done_testing();

# vim: ts=4:sw=4:et

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/payment.t  view on Meta::CPAN

            payout => 'PO456',
            creditor => 'CR001',
        },
    ),
    'Business::GoCardless::Payment'
);

can_ok(
    $Payment,
    qw/
        endpoint
        amount
        amount_refunded
        charge_date
        created_at
        currency
        description
        fx
        id
        links
        metadata

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

        failed
        chargedback
        cancelled
        withdrawn
        refunded
        submitted
        confirmed
    /,
);

is( $Payment->endpoint,'/payments/%s','endpoint' );

$Payment->status( 'unknown' );

ok( ! $Payment->pending,'pending' );
ok( ! $Payment->paid,'paid' );
ok( ! $Payment->failed,'failed' );
ok( ! $Payment->chargedback,'chargedback' );
ok( ! $Payment->cancelled,'cancelled' );
ok( ! $Payment->withdrawn,'withdrawn' );
ok( ! $Payment->refunded,'refunded' );

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

            app_secret  => 'baz',
            merchant_id => 'boz',
        ),
    ),
    'Business::GoCardless::Payout'
);

can_ok(
    $Payout,
    qw/
        endpoint
        amount
        reference
        status

        app_ids
        bank_reference
        paid_at
        transaction_fees

        amount

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

        links
        payout_type
        reference
        status

        pending
        paid
    /,
);

is( $Payout->endpoint,'/payouts/%s','endpoint' );

$Payout->status( 'pending' );
ok( $Payout->pending,'->pending' );
ok( ! $Payout->paid,'->paid' );

$Payout->id( 'PO123' );
is( $Payout->uri,'https://gocardless.com/payouts/PO123','->uri' );

done_testing();

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


        cancel

        inactive
        active
        cancelled
        expired
    /,
);

is( $PreAuthorization->endpoint,'/pre_authorizations/%s','endpoint' );

$PreAuthorization->status( 'unknown' );

ok( ! $PreAuthorization->inactive,'inactive' );
ok( ! $PreAuthorization->active,'active' );
ok( ! $PreAuthorization->cancelled,'cancelled' );
ok( ! $PreAuthorization->expired,'expired' );

done_testing();

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 {} );
*LWP::UserAgent::request = sub { $mock };

test_payment( $GoCardless,$mock );
test_payout( $GoCardless,$mock );
test_pre_authorization( $GoCardless,$mock );

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

  'client' => bless( {
    'api_path' => '',
    'api_version' => 2,
    'base_url' => 'https://api.gocardless.com',
    'token' => 'MvYX0i6snRh/1PXfPoc6',
    'user_agent' => ignore(),
  }, 'Business::GoCardless::Client' ),
  'country_code' => 'GB',
  'created_at' => '2014-05-08T17:01:06.000Z',
  'email' => 'user@example.com',
  'endpoint' => '/customers/%s',
  'family_name' => 'Osbörne',
  'given_name' => 'Frañk',
  'id' => 'CU123',
  'language' => 'en',
  'metadata' => {
    'salesforce_id' => 'ABCD1234'
  },
  'postal_code' => 'E8 3GX',
  'region' => undef,
  'swedish_identity_number' => undef

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

    'api_path' => '',
    'api_version' => 2,
    'base_url' => 'https://api.gocardless.com',
    'token' => 'MvYX0i6snRh/1PXfPoc6',
    'user_agent' => ignore(),
  }, 'Business::GoCardless::Client' ),
  'created_at' => '2014-10-20T17:01:06.000Z',
  'currency' => 'GBP',
  'day_of_month' => 1,
  'end_date' => undef,
  'endpoint' => '/subscriptions/%s',
  'id' => 'SB123',
  'interval' => 1,
  'interval_unit' => 'monthly',
  'links' => {
    'mandate' => 'MA123'
  },
  'metadata' => {
    'order_no' => 'ABCD1234'
  },
  'month' => undef,

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

bless( {
  'client' => bless( {
    'api_path' => '',
    'api_version' => 2,
    'base_url' => 'https://api.gocardless.com',
    'token' => 'MvYX0i6snRh/1PXfPoc6',
    'user_agent' => ignore(),
  }, 'Business::GoCardless::Client' ),
  'created_at' => '2014-10-22T13:10:06.000Z',
  'description' => 'Winé boxes',
  'endpoint' => '/redirect_flows/%s',
  'id' => 'RE123',
  'links' => {
    'creditor' => 'CR123',
    'mandate' => 'MD123'
  },
  'redirect_url' => 'http://pay.gocardless.dev/flow/RE123',
  'scheme' => undef,
  'session_token' => 'SESS_wSs0uGYMISxzqOBq',
  'success_redirect_url' => 'https://example.com/pay/confirm'
}, 'Business::GoCardless::RedirectFlow' );

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


    return 
bless( {
  'client' => bless( {
    'api_path' => '',
    'api_version' => 2,
    'base_url' => 'https://api.gocardless.com',
    'token' => 'MvYX0i6snRh/1PXfPoc6',
    'user_agent' => ignore(),
  }, 'Business::GoCardless::Client' ),
  'endpoint' => '/mandates/%s',
    "id" => "MD000660000000",
    "created_at" => "2017-09-12T20:37:07.787Z",
    "reference" => "MAND-RZ000S",
    "status" => "active",
    "scheme" => "bacs",
    "next_possible_charge_date" => "2017-09-27",
    "payments_require_approval" => JSON::false,
    "metadata" => {},
    "links" => {
        "customer_bank_account" => "BA00060000000W",

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

  'client' => bless( {
    'api_path' => '',
    'api_version' => 2,
    'base_url' => 'https://api.gocardless.com',
    'token' => 'MvYX0i6snRh/1PXfPoc6',
    'user_agent' => ignore(),
  }, 'Business::GoCardless::Client' ),
  'created_at' => '2014-06-20T13:23:34.000Z',
  'currency' => 'GBP',
  'deducted_fees' => 10,
  'endpoint' => '/payouts/%s',
  'fx' => {
    'estimated_exchange_rate' => '1.11667',
    'exchange_rate' => undef,
    'fx_amount' => undef,
    'fx_currency' => 'EUR'
  },
  'id' => 'PO123',
  'links' => {
    'creditor' => 'CR123',
    'creditor_bank_account' => 'BA123'

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


sub _merchant_obj {

    return bless(
        {
            'balance' => '0.0',
            'client' => ignore(),
            'created_at'           => '2014-01-22T10:27:42Z',
            'description'          => 'Wé do stuff.',
            'email'                => 'lee@foo.com',
            'endpoint'             => '/merchants/%s',
            'eur_balance'          => '0.0',
            'eur_pending_balance'  => '0.0',
            'first_name'           => 'Lee',
            'gbp_balance'          => '0.0',
            'gbp_pending_balance'  => '0.0',
            'hide_variable_amount' => JSON::false,
            'id'                   => '06Z06JWQW1',
            'last_name'            => 'Johnson',
            'name'                 => 'Company Ltd',
            'next_payout_amount'   => undef,

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

        "currency"        => "GBP",
        "status"          => $status,
        "reference"       => "WINEBOX001",
        "metadata"        => {
          "order_dispatch_date" => "2014-05-22"
        },
        "links" => {
          "mandate"  => "MD123",
          "creditor" => "CR123",
        },
        'endpoint' => '/payments/%s',
    },'Business::GoCardless::Payment'
    );
}

sub _webhook_payload {

    my ( $signature ) = @_;

    $signature //= '07525beb4617490b433bd9036b97e856cefb041a6401e4f18b228345d34f5fc5';

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

        cancel

        inactive
        active
        cancelled
        expired
        metadata
    /,
);

is( $RedirectFlow->endpoint,'/redirect_flows/%s','endpoint' );

$RedirectFlow->status( 'unknown' );

ok( ! $RedirectFlow->inactive,'inactive' );
ok( ! $RedirectFlow->active,'active' );
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' );

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

        ),
    ),
    'Business::GoCardless::Resource'
);

isa_ok( $TestResource,'TestResource' );

can_ok(
    $TestResource,
    qw/
        endpoint
        client
        to_hash
        to_json
        name
        age
        alive
        time
    /,
);

is( $TestResource->endpoint,'/test_resources/%s','endpoint' );

cmp_deeply(
    { $TestResource->to_hash },
    {
        'age' => 30,
        'alive' => JSON::true,
        'endpoint' => '/test_resources/%s',
        'name' => 'Lee',
        'time' => '2014-08-20T21:41:25Z'
    },
    'to_hash'
);

is(
    $TestResource->to_json,
    JSON->new->canonical->encode( {
        'age' => 30,
        'alive' => JSON::true,
        'endpoint' => '/test_resources/%s',
        'name' => 'Lee',
        'time' => '2014-08-20T21:41:25Z'
    } ),
    'to_json'
);

done_testing();

# vim: ts=4:sw=4:et

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


        cancel

        inactive
        active
        cancelled
        expired
    /,
);

is( $Subscription->endpoint,'/subscriptions/%s','endpoint' );

$Subscription->status( 'unknown' );

ok( ! $Subscription->inactive,'inactive' );
ok( ! $Subscription->active,'active' );
ok( ! $Subscription->cancelled,'cancelled' );
ok( ! $Subscription->expired,'expired' );

done_testing();

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

    $User,
    qw/
        created_at
        email
        first_name
        id
        last_name
    /,
);

is( $User->endpoint,'/users/%s','endpoint' );

done_testing();

# vim: ts=4:sw=4:et

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

ok( !$Webhook->is_pre_authorization,'! is_pre_authorization' );
is( $Webhook->action,'paid','action' );
ok( $Webhook->is_legacy,'->is_legacy' );

cmp_deeply(
    [ $Webhook->resources ],
    [ ( bless( {
        'amount' => '20.0',
        'amount_minus_fees' => '19.8',
        'client' => ignore(),
        'endpoint' => '/bills/%s',
        'id' => ignore(),
        'paid_at' => ignore(),
        'source_id' => ignore(),
        'source_type' => 'subscription',
        'status' => 'paid',
        'uri' => ignore(),
        },'Business::GoCardless::Bill' ) ) x 2
    ],
    'resources'
);

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

    bless( {
        'action' => 'paid_out',
        'client' => bless( {
          'api_version' => 1,
          'base_url' => 'https://gocardless.com',
          'token' => 'foo',
          'user_agent' => ignore(),
          'webhook_secret' => 'bar'
        }, 'Business::GoCardless::Client' ),
        'created_at' => '2017-09-11T14:05:35.461Z',
        'endpoint' => '/events/%s',
        'id' => 'EV789',
        'links' => {
          'parent_event' => 'EV123',
          'payment' => 'PM456',
          'payout' => 'PO123'
        },
        'details' => {
          'cause' => 'payment_paid_out',
          'description' => 'The payment has been paid out by GoCardless.',
          'origin' => 'gocardless'

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

ok( !$Webhook->is_pre_authorization,'! is_pre_authorization' );
is( $Webhook->action,'paid','action' );
ok( $Webhook->is_legacy,'->is_legacy' );

cmp_deeply(
    [ $Webhook->resources ],
    [ ( bless( {
        'amount' => '20.0',
        'amount_minus_fees' => '19.8',
        'client' => ignore(),
        'endpoint' => '/bills/%s',
        'id' => ignore(),
        'paid_at' => ignore(),
        'source_id' => ignore(),
        'source_type' => 'subscription',
        'status' => 'paid',
        'uri' => ignore(),
        },'Business::GoCardless::Bill' ) ) x 2
    ],
    'resources'
);



( run in 0.482 second using v1.01-cache-2.11-cpan-b61123c0432 )