« lib/WebService/Braintree/PaymentMethodGatewayBase.pm
↑ Summary
lib/WebService/Braintree/MerchantAccountGateway.pm »
| 1 | # vim: sw=4 ts=4 ft=perl | ||||||||||||||
| 2 | |||||||||||||||
| 3 | package # hide from pause | ||||||||||||||
| 4 | WebService::Braintree::SubscriptionGateway; | ||||||||||||||
| 5 | |||||||||||||||
| 6 | 22 | ▶ | use 5.010_001; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 22 | ▶ | use strictures 1; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 22 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 22 | with 'WebService::Braintree::Role::MakeRequest'; | |||||||||||||
| 11 | 22 | with 'WebService::Braintree::Role::CollectionBuilder'; | |||||||||||||
| 12 | |||||||||||||||
| 13 | 22 | ▶ | use Carp qw(confess); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | 22 | ▶ | use WebService::Braintree::Util qw(validate_id); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | 22 | ▶ | use WebService::Braintree::Validations qw(verify_params); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | |||||||||||||||
| 18 | 22 | ▶ | use WebService::Braintree::_::Subscription; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | 22 | ▶ | use WebService::Braintree::SubscriptionSearch; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 20 | |||||||||||||||
| 21 | 0 | ▶ | sub create { | ||||||||||||
|
Subroutine
create: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 22 | 0 | my ($self, $params) = @_; | |||||||||||||
| 23 | |||||||||||||||
| 24 | 0 | ▶ | confess "ArgumentError" unless verify_params($params, _signature_for('create')); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 25 | |||||||||||||||
| 26 | 0 | my $result = $self->_make_request("/subscriptions/", "post", {subscription => $params}); | |||||||||||||
| 27 | 0 | return $result; | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | |||||||||||||||
| 30 | 2 | ▶ | sub find { | ||||||||||||
|
Subroutine
find: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||
| 31 | 2 | my ($self, $id) = @_; | |||||||||||||
| 32 | 2 | ▶ | confess "NotFoundError" unless validate_id($id); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 33 | 0 | my $result = $self->_make_request("/subscriptions/$id", "get", undef)->subscription; | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | |||||||||||||||
| 36 | 0 | ▶ | sub update { | ||||||||||||
|
Subroutine
update: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 37 | 0 | my ($self, $id, $params) = @_; | |||||||||||||
| 38 | |||||||||||||||
| 39 | 0 | ▶ | confess "NotFoundError" unless validate_id($id); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 40 | 0 | ▶ | confess "ArgumentError" unless verify_params($params, _signature_for('update')); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | |||||||||||||||
| 42 | 0 | my $result = $self->_make_request("/subscriptions/$id", "put", {subscription => $params}); | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | |||||||||||||||
| 45 | 0 | ▶ | sub cancel { | ||||||||||||
|
Subroutine
cancel: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 46 | 0 | my ($self, $id) = @_; | |||||||||||||
| 47 | 0 | ▶ | confess "NotFoundError" unless validate_id($id); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 48 | 0 | my $result = $self->_make_request("/subscriptions/$id/cancel", "put", undef); | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 0 | ▶ | sub search { | ||||||||||||
|
Subroutine
search: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 52 | 0 | my ($self, $block) = @_; | |||||||||||||
| 53 | |||||||||||||||
| 54 | 0 | return $self->resource_collection({ | |||||||||||||
| 55 | ids_url => "/subscriptions/advanced_search_ids", | ||||||||||||||
| 56 | obj_url => "/subscriptions/advanced_search", | ||||||||||||||
| 57 | inflate => [qw/subscriptions subscription _::Subscription/], | ||||||||||||||
| 58 | search => $block->(WebService::Braintree::SubscriptionSearch->new), | ||||||||||||||
| 59 | }); | ||||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 0 | ▶ | sub all { | ||||||||||||
|
Subroutine
all: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||||
| 64 | |||||||||||||||
| 65 | 0 | return $self->resource_collection({ | |||||||||||||
| 66 | ids_url => "/subscriptions/advanced_search_ids", | ||||||||||||||
| 67 | obj_url => "/subscriptions/advanced_search", | ||||||||||||||
| 68 | inflate => [qw/subscriptions subscription _::Subscription/], | ||||||||||||||
| 69 | }); | ||||||||||||||
| 70 | } | ||||||||||||||
| 71 | |||||||||||||||
| 72 | 0 | ▶ | sub _signature_for { | ||||||||||||
|
Subroutine
_signature_for: not called CC=3 SCAR=24.8
| |||||||||||||||
| 73 | 0 | my ($type) = @_; | |||||||||||||
| 74 | |||||||||||||||
| 75 | 0 | my $signature = { | |||||||||||||
| 76 | id => 1, | ||||||||||||||
| 77 | merchant_account_id => 1, | ||||||||||||||
| 78 | never_expires => 1, | ||||||||||||||
| 79 | number_of_billing_cycles => 1, | ||||||||||||||
| 80 | payment_method_nonce => 1, | ||||||||||||||
| 81 | payment_method_token => 1, | ||||||||||||||
| 82 | plan_id => 1, | ||||||||||||||
| 83 | price => 1, | ||||||||||||||
| 84 | options => { | ||||||||||||||
| 85 | paypal => { | ||||||||||||||
| 86 | description => 1, | ||||||||||||||
| 87 | }, | ||||||||||||||
| 88 | }, | ||||||||||||||
| 89 | add_ons => { | ||||||||||||||
| 90 | add => '_any_key_', | ||||||||||||||
| 91 | update => '_any_key_', | ||||||||||||||
| 92 | remove => '_any_key_', | ||||||||||||||
| 93 | }, | ||||||||||||||
| 94 | discounts => { | ||||||||||||||
| 95 | add => '_any_key_', | ||||||||||||||
| 96 | update => '_any_key_', | ||||||||||||||
| 97 | remove => '_any_key_', | ||||||||||||||
| 98 | }, | ||||||||||||||
| 99 | descriptor => { | ||||||||||||||
| 100 | name => 1, | ||||||||||||||
| 101 | phone => 1, | ||||||||||||||
| 102 | url => 1, | ||||||||||||||
| 103 | }, | ||||||||||||||
| 104 | }; | ||||||||||||||
| 105 | |||||||||||||||
| 106 | 0 | ▶ | if ($type eq 'create') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 107 | $signature = { | ||||||||||||||
| 108 | 0 | %{$signature}, | |||||||||||||
| 109 | billing_day_of_month => 1, | ||||||||||||||
| 110 | first_billing_date => 1, | ||||||||||||||
| 111 | trial_duration => 1, | ||||||||||||||
| 112 | trial_duration_unit => 1, | ||||||||||||||
| 113 | trial_period => 1, | ||||||||||||||
| 114 | }; | ||||||||||||||
| 115 | $signature->{options} = { | ||||||||||||||
| 116 | 0 | %{$signature->{options}}, | |||||||||||||
| 117 | do_not_inherit_add_ons_or_discounts => 1, | ||||||||||||||
| 118 | start_immediately => 1, | ||||||||||||||
| 119 | }; | ||||||||||||||
| 120 | } | ||||||||||||||
| 121 | elsif ($type eq 'update') { | ||||||||||||||
| 122 | $signature->{options} = { | ||||||||||||||
| 123 | 0 | %{$signature->{options}}, | |||||||||||||
| 124 | prorate_charges => 1, | ||||||||||||||
| 125 | replace_all_add_ons_and_discounts => 1, | ||||||||||||||
| 126 | revert_subscription_on_proration_failure => 1, | ||||||||||||||
| 127 | }; | ||||||||||||||
| 128 | } | ||||||||||||||
| 129 | |||||||||||||||
| 130 | 0 | return $signature; | |||||||||||||
| 131 | } | ||||||||||||||
| 132 | |||||||||||||||
| 133 | 22 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 134 | |||||||||||||||
| 135 | 22 | 1; | |||||||||||||
| 136 | __END__ | ||||||||||||||