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