| 1 | package WWW::PayPal::API::Orders; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: PayPal Checkout / Orders v2 API | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use WWW::PayPal::Order; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | has client => ( | |||||||||||||||||||||||||||
| 14 | is => 'ro', | ||||||||||||||||||||||||||||
| 15 | required => 1, | ||||||||||||||||||||||||||||
| 16 | weak_ref => 1, | ||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | has openapi_operations => ( | ||||||||||||||||||||||||||||
| 21 | is => 'lazy', | ||||||||||||||||||||||||||||
| 22 | builder => sub { | ||||||||||||||||||||||||||||
| 23 | # Pre-computed from paypal-rest-api-specifications | ||||||||||||||||||||||||||||
| 24 | # (openapi/checkout_orders_v2.json). Regenerate manually when the | ||||||||||||||||||||||||||||
| 25 | # spec changes. | ||||||||||||||||||||||||||||
| 26 | return { | ||||||||||||||||||||||||||||
| 27 | 1 | ▶ | 'orders.create' => { method => 'POST', path => '/v2/checkout/orders' }, | ||||||||||||||||||||||||||
|
Subroutine
_build_openapi_operations: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 'orders.get' => { method => 'GET', path => '/v2/checkout/orders/{id}' }, | ||||||||||||||||||||||||||||
| 29 | 'orders.patch' => { method => 'PATCH', path => '/v2/checkout/orders/{id}' }, | ||||||||||||||||||||||||||||
| 30 | 'orders.confirm' => { method => 'POST', path => '/v2/checkout/orders/{id}/confirm-payment-source' }, | ||||||||||||||||||||||||||||
| 31 | 'orders.authorize' => { method => 'POST', path => '/v2/checkout/orders/{id}/authorize' }, | ||||||||||||||||||||||||||||
| 32 | 'orders.capture' => { method => 'POST', path => '/v2/checkout/orders/{id}/capture' }, | ||||||||||||||||||||||||||||
| 33 | }; | ||||||||||||||||||||||||||||
| 34 | }, | ||||||||||||||||||||||||||||
| 35 | 2 | ); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 | with 'WWW::PayPal::Role::OpenAPI'; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub _wrap { | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | my ($self, $data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_wrap: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 42 | 0 | return WWW::PayPal::Order->new(client => $self->client, data => $data); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub create { | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
create: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | croak 'intent required' unless $args{intent}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | croak 'purchase_units required' | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | unless ref $args{purchase_units} eq 'ARRAY' && @{$args{purchase_units}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $args{"purchase_units"} eq "ARRAY" and @{$args{"purchase_units"};}
MC/DC0%0/2
ref $args{"purchase_units"} eq "ARRAY" and @{$args{"purchase_units"};}
ref $args{"purchase_units"} eq "ARRAY"
@{$args{"purchase_units"};}
Truth table0%0/3
A and B
A= ref $args{"purchase_units"} eq "ARRAY"B= @{$args{"purchase_units"};}
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | my $body = { | ||||||||||||||||||||||||||||
| 53 | intent => $args{intent}, | ||||||||||||||||||||||||||||
| 54 | purchase_units => $args{purchase_units}, | ||||||||||||||||||||||||||||
| 55 | 0 | }; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # Application context: return/cancel URLs and branding | ||||||||||||||||||||||||||||
| 58 | 0 | my %ctx; | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | $ctx{return_url} = $args{return_url} if $args{return_url}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $ctx{cancel_url} = $args{cancel_url} if $args{cancel_url}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | $ctx{brand_name} = $args{brand_name} if $args{brand_name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | $ctx{locale} = $args{locale} if $args{locale}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $ctx{user_action} = $args{user_action} // 'PAY_NOW'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"user_action"} // "PAY_NOW"
MC/DC0%0/1
$args{"user_action"} // "PAY_NOW"
$args{"user_action"}
Truth table0%0/2
A
A= $args{"user_action"}
| |||||||||||||||||||||||||||||
| 64 | $ctx{shipping_preference} = $args{shipping_preference} | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if $args{shipping_preference}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if (%ctx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | # PayPal supports both payment_source.paypal.experience_context (new) | ||||||||||||||||||||||||||||
| 68 | # and application_context (legacy). We use application_context for | ||||||||||||||||||||||||||||
| 69 | # broad compatibility. | ||||||||||||||||||||||||||||
| 70 | 0 | $body->{application_context} = \%ctx; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $body->{payer} = $args{payer} if $args{payer}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | my $data = $self->call_operation('orders.create', body => $body); | |||||||||||||||||||||||||||
| 76 | 0 | return $self->_wrap($data); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub get { | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | croak 'order id required' unless $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | my $data = $self->call_operation('orders.get', path => { id => $id }); | |||||||||||||||||||||||||||
| 84 | 0 | return $self->_wrap($data); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | sub capture { | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my ($self, $id, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
capture: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | croak 'order id required' unless $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | my $data = $self->call_operation('orders.capture', | ||||||||||||||||||||||||||||
| 93 | path => { id => $id }, | ||||||||||||||||||||||||||||
| 94 | body => $args{body} || {}, | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{'body'} || {}
MC/DC0%0/1
$args{'body'} || {}
$args{'body'}
Truth table0%0/2
A
A= $args{'body'}
| |||||||||||||||||||||||||||||
| 96 | 0 | return $self->_wrap($data); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | sub authorize { | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my ($self, $id, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
authorize: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | croak 'order id required' unless $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | my $data = $self->call_operation('orders.authorize', | ||||||||||||||||||||||||||||
| 104 | path => { id => $id }, | ||||||||||||||||||||||||||||
| 105 | body => $args{body} || {}, | ||||||||||||||||||||||||||||
| 106 | 0 | ▶ | ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{'body'} || {}
MC/DC0%0/1
$args{'body'} || {}
$args{'body'}
Truth table0%0/2
A
A= $args{'body'}
| |||||||||||||||||||||||||||||
| 107 | 0 | return $self->_wrap($data); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 2 | 1; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | __END__ | ||||||||||||||||||||||||||||