| 1 | package WebService::PayPal::PaymentsAdvanced::Mocker; | ||||||||||
| 2 | |||||||||||
| 3 | 6 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 6 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 6 | our $VERSION = '0.000028'; | |||||||||
| 8 | |||||||||||
| 9 | 6 | ▶ | use Types::Standard qw( Bool CodeRef InstanceOf ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 6 | ▶ | use WebService::PayPal::PaymentsAdvanced::Mocker::PayflowLink (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 6 | ▶ | use WebService::PayPal::PaymentsAdvanced::Mocker::PayflowPro (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 6 | has mocked_ua => ( | |||||||||
| 14 | is => 'ro', | ||||||||||
| 15 | isa => InstanceOf ['Test::LWP::UserAgent'], | ||||||||||
| 16 | init_arg => undef, | ||||||||||
| 17 | lazy => 1, | ||||||||||
| 18 | builder => '_build_mocked_ua', | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | # The app builders return different things under different conditions. The | ||||||||||
| 22 | # return a CodeRef under Plack. They return a Mojolicious::Lite object when | ||||||||||
| 23 | # deployed via morbo. They return a "1" when not run via Plack, using the test | ||||||||||
| 24 | # suite. | ||||||||||
| 25 | |||||||||||
| 26 | 6 | has payflow_link => ( | |||||||||
| 27 | is => 'ro', | ||||||||||
| 28 | isa => CodeRef | InstanceOf ['Mojolicious::Lite'] | Bool, | ||||||||||
| 29 | init_arg => undef, | ||||||||||
| 30 | lazy => 1, | ||||||||||
| 31 | builder => '_build_payflow_link', | ||||||||||
| 32 | ); | ||||||||||
| 33 | |||||||||||
| 34 | 6 | has payflow_pro => ( | |||||||||
| 35 | is => 'ro', | ||||||||||
| 36 | isa => CodeRef | InstanceOf ['Mojolicious::Lite'] | Bool, | ||||||||||
| 37 | init_arg => undef, | ||||||||||
| 38 | lazy => 1, | ||||||||||
| 39 | builder => '_build_payflow_pro', | ||||||||||
| 40 | ); | ||||||||||
| 41 | |||||||||||
| 42 | 6 | has plack => ( | |||||||||
| 43 | is => 'ro', | ||||||||||
| 44 | isa => Bool, | ||||||||||
| 45 | init_arg => 'plack', | ||||||||||
| 46 | default => 0, | ||||||||||
| 47 | ); | ||||||||||
| 48 | |||||||||||
| 49 | 6 | has _ua => ( | |||||||||
| 50 | is => 'ro', | ||||||||||
| 51 | isa => InstanceOf ['Test::LWP::UserAgent'], | ||||||||||
| 52 | init_arg => 'ua', | ||||||||||
| 53 | lazy => 1, | ||||||||||
| 54 | builder => '_build_ua', | ||||||||||
| 55 | ); | ||||||||||
| 56 | |||||||||||
| 57 | 28 | ▶ | sub _build_ua { | ||||||||
|
Subroutine
_build_ua: called CC=2 SCAR=7.0
| |||||||||||
| 58 | 28 | my $self = shift; | |||||||||
| 59 | |||||||||||
| 60 | 28 | ▶ | die 'plack => 1 is required for mocking via useragent' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | unless $self->plack; | ||||||||||
| 62 | |||||||||||
| 63 | 28 | require Test::LWP::UserAgent; | |||||||||
| 64 | |||||||||||
| 65 | 28 | my $ua = Test::LWP::UserAgent->new( network_fallback => 0 ); | |||||||||
| 66 | 28 | return $ua; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 28 | ▶ | sub _build_mocked_ua { | ||||||||
|
Subroutine
_build_mocked_ua: called CC=1 SCAR=0.0
| |||||||||||
| 70 | 28 | my $self = shift; | |||||||||
| 71 | |||||||||||
| 72 | 28 | require HTTP::Message::PSGI; | |||||||||
| 73 | |||||||||||
| 74 | 28 | my $link = $self->payflow_link; | |||||||||
| 75 | 28 | my $pro = $self->payflow_pro; | |||||||||
| 76 | |||||||||||
| 77 | 28 | $self->_ua->register_psgi( 'payflowlink.paypal.com', $link ); | |||||||||
| 78 | 28 | $self->_ua->register_psgi( 'payflowpro.paypal.com', $pro ); | |||||||||
| 79 | 28 | $self->_ua->register_psgi( 'pilot-payflowlink.paypal.com', $link ); | |||||||||
| 80 | 28 | $self->_ua->register_psgi( 'pilot-payflowpro.paypal.com', $pro ); | |||||||||
| 81 | |||||||||||
| 82 | 28 | return $self->_ua; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 29 | ▶ | sub _build_payflow_link { | ||||||||
|
Subroutine
_build_payflow_link: called CC=2 SCAR=6.9
| |||||||||||
| 86 | 29 | my $self = shift; | |||||||||
| 87 | |||||||||||
| 88 | 29 | ▶ | local $ENV{PLACK_ENV} = 'development' if $self->plack; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | 29 | return WebService::PayPal::PaymentsAdvanced::Mocker::PayflowLink->to_app; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 31 | ▶ | sub _build_payflow_pro { | ||||||||
|
Subroutine
_build_payflow_pro: called CC=2 SCAR=6.9
| |||||||||||
| 93 | 31 | my $self = shift; | |||||||||
| 94 | |||||||||||
| 95 | 31 | ▶ | local $ENV{PLACK_ENV} = 'development' if $self->plack; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | 31 | return WebService::PayPal::PaymentsAdvanced::Mocker::PayflowPro->to_app; | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 6 | 1; | |||||||||
| 100 | |||||||||||
| 101 | # ABSTRACT: A class which returns mocked PPA apps. | ||||||||||
| 102 | |||||||||||
| 103 | __END__ | ||||||||||