File Coverage

blib/lib/Net/Braintree/CreditCardGateway.pm
Criterion Covered Total %
statement 18 38 47.3
branch 0 8 0.0
condition n/a
subroutine 6 14 42.8
pod 0 5 0.0
total 24 65 36.9


line stmt bran cond sub pod time code
1             package Net::Braintree::CreditCardGateway;
2 1     1   3 use Moose;
  1         2  
  1         5  
3 1     1   3825 use Carp qw(confess);
  1         2  
  1         45  
4 1     1   4 use Net::Braintree::Validations qw(verify_params credit_card_signature);
  1         0  
  1         38  
5 1     1   4 use Net::Braintree::Util qw(validate_id);
  1         1  
  1         36  
6 1     1   4 use Net::Braintree::Result;
  1         2  
  1         14  
7 1     1   4 use Try::Tiny;
  1         1  
  1         342  
8              
9             has 'gateway' => (is => 'ro');
10              
11             sub create {
12 0     0 0   my ($self, $params) = @_;
13 0 0         confess "ArgumentError" unless verify_params($params, credit_card_signature);
14 0           $self->_make_request("/payment_methods/", "post", {credit_card => $params});
15             }
16              
17             sub delete {
18 0     0 0   my ($self, $token) = @_;
19 0           $self->_make_request("/payment_methods/credit_card/$token", "delete", undef);
20             }
21              
22             sub update {
23 0     0 0   my ($self, $token, $params) = @_;
24 0 0         confess "ArgumentError" unless verify_params($params, credit_card_signature);
25 0           $self->_make_request("/payment_methods/credit_card/$token", "put", {credit_card => $params});
26             }
27              
28             sub find {
29 0     0 0   my ($self, $token) = @_;
30 0 0         confess "NotFoundError" unless validate_id($token);
31 0           $self->_make_request("/payment_methods/credit_card/$token", "get", undef)->credit_card;
32             }
33              
34             sub from_nonce {
35 0     0 0   my ($self, $nonce) = @_;
36 0 0         confess "NotFoundError" unless validate_id($nonce);
37              
38             try {
39 0     0     return $self->_make_request("/payment_methods/from_nonce/$nonce", "get", undef)->credit_card;
40             } catch {
41 0     0     confess "Payment method with nonce $nonce locked, consumed or not found";
42             }
43 0           }
44              
45             sub _make_request {
46 0     0     my($self, $path, $verb, $params) = @_;
47 0           my $response = $self->gateway->http->$verb($path, $params);
48 0           my $result = Net::Braintree::Result->new(response => $response);
49 0           return $result;
50             }
51              
52             1;