File Coverage

blib/lib/WebService/Braintree/CreditCard.pm
Criterion Covered Total %
statement 33 55 60.0
branch 0 2 0.0
condition n/a
subroutine 11 22 50.0
pod 8 11 72.7
total 52 90 57.7


line stmt bran cond sub pod time code
1             package WebService::Braintree::CreditCard;
2             $WebService::Braintree::CreditCard::VERSION = '0.92';
3 1     1   236 use WebService::Braintree::CreditCard::CardType;
  1         5  
  1         37  
4 1     1   258 use WebService::Braintree::CreditCard::Location;
  1         2  
  1         32  
5 1     1   236 use WebService::Braintree::CreditCard::Prepaid;
  1         5  
  1         37  
6 1     1   233 use WebService::Braintree::CreditCard::Debit;
  1         3  
  1         22  
7 1     1   233 use WebService::Braintree::CreditCard::Payroll;
  1         3  
  1         20  
8 1     1   226 use WebService::Braintree::CreditCard::Healthcare;
  1         3  
  1         21  
9 1     1   224 use WebService::Braintree::CreditCard::DurbinRegulated;
  1         2  
  1         21  
10 1     1   225 use WebService::Braintree::CreditCard::Commercial;
  1         3  
  1         21  
11 1     1   234 use WebService::Braintree::CreditCard::CountryOfIssuance;
  1         2  
  1         20  
12 1     1   223 use WebService::Braintree::CreditCard::IssuingBank;
  1         2  
  1         23  
13              
14             =head1 NAME
15              
16             WebService::Braintree::CreditCard
17              
18             =head1 PURPOSE
19              
20             This class creates, updates, deletes, and finds credit cards.
21              
22             =cut
23              
24 1     1   5 use Moose;
  1         2  
  1         5  
25             extends 'WebService::Braintree::PaymentMethod';
26              
27             =head1 CLASS METHODS
28              
29             =head2 create()
30              
31             This takes a hashref of parameters and returns the credit card created.
32              
33             =cut
34              
35             sub create {
36 0     0 1   my ($class, $params) = @_;
37 0           $class->gateway->credit_card->create($params);
38             }
39              
40             =head2 create()
41              
42             This takes a nonce and returns the credit card (if it exists).
43              
44             =cut
45              
46             sub from_nonce {
47 0     0 0   my ($class, $nonce) = @_;
48 0           $class->gateway->credit_card->from_nonce($nonce);
49             }
50              
51             =head2 find()
52              
53             This takes a token and returns the credit card (if it exists).
54              
55             =cut
56              
57             sub find {
58 0     0 1   my ($class, $token) = @_;
59 0           $class->gateway->credit_card->find($token);
60             }
61              
62             =head2 update()
63              
64             This takes a token and a hashref of parameters. It will update the
65             corresponding credit card (if found) and returns the updated credit card.
66              
67             =cut
68              
69             sub update {
70 0     0 1   my($class, $token, $params) = @_;
71 0           $class->gateway->credit_card->update($token, $params);
72             }
73              
74             =head2 update()
75              
76             This takes a token. It will delete the corresponding credit card (if found).
77              
78             =cut
79              
80             sub delete {
81 0     0 1   my ($class, $token) = @_;
82 0           $class->gateway->credit_card->delete($token);
83             }
84              
85             sub gateway {
86 0     0 0   WebService::Braintree->configuration->gateway;
87             }
88              
89             =head1 OBJECT METHODS
90              
91             In addition to the methods provided by the keys returned from Braintree, this
92             class provides the following methods:
93              
94             =head2 billing_address()
95              
96             This returns the credit card's billing address (if it exists). This will be an
97             object of type L<WebService::Braintree::Address/>.
98              
99             =cut
100              
101             has billing_address => (is => 'rw');
102              
103             sub BUILD {
104 0     0 0   my ($self, $attributes) = @_;
105 0 0         $self->billing_address(WebService::Braintree::Address->new($attributes->{billing_address})) if ref($attributes->{billing_address}) eq 'HASH';
106 0           delete($attributes->{billing_address});
107 0           $self->set_attributes_from_hash($self, $attributes);
108             }
109              
110             =head2 masked_number()
111              
112             This returns a masked credit card number suitable for display.
113              
114             =cut
115              
116             sub masked_number {
117 0     0 1   my $self = shift;
118 0           return $self->bin . "******" . $self->last_4;
119             }
120              
121             =head2 expiration_date()
122              
123             This returns the credit card's expiration in MM/YY format.
124              
125             =cut
126              
127             sub expiration_date {
128 0     0 1   my $self = shift;
129 0           return $self->expiration_month . "/" . $self->expiration_year;
130             }
131              
132             =head2 is_default()
133              
134             This returns true if this credit card is the default credit card.
135              
136             =cut
137              
138             sub is_default {
139 0     0 1   return shift->default;
140             }
141              
142             =head2 is_venmo_sdk()
143              
144             This returns true if this credit card uses the Venmo SDK.
145              
146             =cut
147              
148             sub is_venmo_sdk {
149 0     0 1   my $self = shift;
150 0           return $self->venmo_sdk;
151             }
152              
153             __PACKAGE__->meta->make_immutable;
154              
155             1;
156             __END__
157              
158             =head1 NOTES
159              
160             Most of the classes normally used in WebService::Braintree inherit from
161             L<WebService::Braintree::ResultObject/>. This class, however, inherits from
162             L<WebService::Braintree::PaymentMethod/>. The primary benefit of this is that
163             these objects have a C<< token() >> attribute.
164              
165             =head1 TODO
166              
167             =over 4
168              
169             =item Need to document the keys and values that are returned
170              
171             =item Need to document the required and optional input parameters
172              
173             =item Need to document the possible errors/exceptions
174              
175             =back
176              
177             =cut