File Coverage

lib/WebService/Braintree/Customer.pm
Criterion Covered Total %
statement 8 31 25.8
branch n/a
condition 0 2 0.0
subroutine 3 13 23.0
pod 8 10 80.0
total 19 56 33.9


line stmt bran cond sub pod time code
1             package WebService::Braintree::Customer;
2             $WebService::Braintree::Customer::VERSION = '0.94';
3 20     20   369 use 5.010_001;
  20         61  
4 20     20   101 use strictures 1;
  20         125  
  20         778  
5              
6             =head1 NAME
7              
8             WebService::Braintree::Customer
9              
10             =head1 PURPOSE
11              
12             This class creates, updates, deletes, and finds customers.
13              
14             =cut
15              
16 20     20   1911 use Moose;
  20         35  
  20         106  
17             extends 'WebService::Braintree::ResultObject';
18              
19             =head2 create()
20              
21             This takes a hashref of parameters and returns the customer created.
22              
23             =cut
24              
25             sub create {
26 0     0 1   my ($class, $params) = @_;
27 0           $class->gateway->customer->create($params);
28             }
29              
30             =head2 find()
31              
32             This takes a customer_id returns the customer (if it exists).
33              
34             =cut
35              
36             sub find {
37 0     0 1   my($class, $id) = @_;
38 0           $class->gateway->customer->find($id);
39             }
40              
41             =head2 update()
42              
43             This takes a customer_id and a hashref of parameters. It will update the
44             corresponding customer (if found) and returns the updated customer.
45              
46             =cut
47              
48             sub update {
49 0     0 1   my ($class, $id, $params) = @_;
50 0           $class->gateway->customer->update($id, $params);
51             }
52              
53             =head2 delete()
54              
55             This takes a customer_id and deletes the corresponding customer (if found).
56              
57             =cut
58              
59             sub delete {
60 0     0 1   my ($class, $id) = @_;
61 0           $class->gateway->customer->delete($id);
62             }
63              
64             =head2 search()
65              
66             This takes a subref which is used to set the search parameters and returns a
67             customer object.
68              
69             Please see L<Searching|WebService::Braintree/SEARCHING> for more information on
70             the subref and how it works.
71              
72             =cut
73              
74             sub search {
75 0     0 1   my ($class, $block) = @_;
76 0           $class->gateway->customer->search($block);
77             }
78              
79             =head2 all()
80              
81             This returns all the customers.
82              
83             =cut
84              
85             sub all {
86 0     0 1   my ($class) = @_;
87 0           $class->gateway->customer->all;
88             }
89              
90             sub gateway {
91 0     0 0   return WebService::Braintree->configuration->gateway;
92             }
93              
94             sub BUILD {
95 0     0 0   my ($self, $attributes) = @_;
96 0           my $sub_objects = {
97             addresses => "WebService::Braintree::Address",
98             credit_cards => "WebService::Braintree::CreditCard",
99             paypal_accounts => "WebService::Braintree::PayPalAccount",
100             };
101              
102 0           $self->setup_sub_objects($self, $attributes, $sub_objects);
103 0           $self->set_attributes_from_hash($self, $attributes);
104             }
105              
106             =head1 OBJECT METHODS
107              
108             In addition to the methods provided by the keys returned from Braintree, this
109             class provides the following methods:
110              
111             =head2 payment_types()
112              
113             This returns a list of all the payment types supported by this class.
114              
115             =cut
116              
117             sub payment_types {
118 0     0 1   return qw(credit_cards paypal_accounts);
119             }
120              
121             =head2 payment_methods()
122              
123             This returns an arrayref of all available payment methods across all types.
124              
125             =cut
126              
127             sub payment_methods {
128 0     0 1   my $self = shift;
129              
130             my @methods = map {
131 0   0       @{$self->$_ // []}
  0            
  0            
132             } $self->payment_types;
133              
134 0           return \@methods;
135             }
136              
137             __PACKAGE__->meta->make_immutable;
138              
139             1;
140             __END__
141              
142             =head1 TODO
143              
144             =over 4
145              
146             =item Need to document the keys and values that are returned
147              
148             =item Need to document the required and optional input parameters
149              
150             =item Need to document the possible errors/exceptions
151              
152             =back
153              
154             =cut