File Coverage

blib/lib/Net/Braintree/TransactionGateway.pm
Criterion Covered Total %
statement 15 60 25.0
branch 0 10 0.0
condition n/a
subroutine 5 21 23.8
pod 0 13 0.0
total 20 104 19.2


line stmt bran cond sub pod time code
1             package Net::Braintree::TransactionGateway;
2 1     1   5 use Moose;
  1         2  
  1         6  
3 1     1   5307 use Carp qw(confess);
  1         2  
  1         63  
4 1     1   5 use Net::Braintree::Util qw(validate_id);
  1         2  
  1         45  
5 1     1   5 use Net::Braintree::Validations qw(verify_params transaction_signature clone_transaction_signature transaction_search_results_signature);
  1         1  
  1         50  
6 1     1   5 use Net::Braintree::Util;
  1         1  
  1         846  
7              
8             has 'gateway' => (is => 'ro');
9              
10             sub create {
11 0     0 0   my ($self, $params) = @_;
12 0 0         confess "ArgumentError" unless verify_params($params, transaction_signature);
13 0           $self->_make_request("/transactions/", "post", {transaction => $params});
14             }
15              
16             sub find {
17 0     0 0   my ($self, $id) = @_;
18 0 0         confess "NotFoundError" unless validate_id($id);
19 0           $self->_make_request("/transactions/$id", "get", undef);
20             }
21              
22             sub retry_subscription_charge {
23 0     0 0   my ($self, $subscription_id, $amount) = @_;
24 0           my $params = {
25             subscription_id => $subscription_id,
26             amount => $amount,
27             type => "sale"
28             };
29              
30 0           $self->create($params);
31             }
32              
33             sub submit_for_settlement {
34 0     0 0   my ($self, $id, $params) = @_;
35 0           $self->_make_request("/transactions/$id/submit_for_settlement", "put", {transaction => $params});
36             }
37              
38             sub void {
39 0     0 0   my ($self, $id) = @_;
40 0           $self->_make_request("/transactions/$id/void", "put", undef);
41             }
42              
43             sub refund {
44 0     0 0   my ($self, $id, $params) = @_;
45 0           $self->_make_request("/transactions/$id/refund", "post", {transaction => $params});
46             }
47              
48             sub clone_transaction {
49 0     0 0   my ($self, $id, $params) = @_;
50 0 0         confess "ArgumentError" unless verify_params($params, clone_transaction_signature);
51 0           $self->_make_request("/transactions/$id/clone", "post", {transaction_clone => $params});
52             }
53              
54             sub search {
55 0     0 0   my ($self, $block) = @_;
56 0           my $search = Net::Braintree::TransactionSearch->new;
57 0           my $params = $block->($search)->to_hash;
58 0           my $response = $self->gateway->http->post("/transactions/advanced_search_ids", {search => $params});
59 0 0         confess "DownForMaintenanceError" unless (verify_params($response, transaction_search_results_signature));
60             return Net::Braintree::ResourceCollection->new()->init($response, sub {
61 0     0     $self->fetch_transactions($search, shift);
62 0           });
63             }
64              
65             sub hold_in_escrow {
66 0     0 0   my ($self, $id) = @_;
67 0           $self->_make_request("/transactions/$id/hold_in_escrow", "put", undef);
68             }
69              
70             sub release_from_escrow {
71 0     0 0   my ($self, $id) = @_;
72 0           $self->_make_request("/transactions/$id/release_from_escrow", "put", undef);
73             }
74              
75             sub cancel_release {
76 0     0 0   my ($self, $id) = @_;
77 0           $self->_make_request("/transactions/$id/cancel_release", "put", undef);
78             }
79              
80             sub all {
81 0     0 0   my $self = shift;
82 0           my $response = $self->gateway->http->post("/transactions/advanced_search_ids");
83             return Net::Braintree::ResourceCollection->new()->init($response, sub {
84 0     0     $self->fetch_transactions(Net::Braintree::TransactionSearch->new, shift);
85 0           });
86             }
87              
88             sub _make_request {
89 0     0     my($self, $path, $verb, $params) = @_;
90 0           my $response = $self->gateway->http->$verb($path, $params);
91 0           return Net::Braintree::Result->new(response => $response);
92             }
93              
94             sub fetch_transactions {
95 0     0 0   my ($self, $search, $ids) = @_;
96 0           $search->ids->in($ids);
97 0 0         return [] if scalar @{$ids} == 0;
  0            
98 0           my $response = $self->gateway->http->post("/transactions/advanced_search/", {search => $search->to_hash});
99 0           my $attrs = $response->{'credit_card_transactions'}->{'transaction'};
100 0           return to_instance_array($attrs, "Net::Braintree::Transaction");
101             }
102              
103             1;