File Coverage

blib/lib/WebService/Braintree.pm
Criterion Covered Total %
statement 79 81 97.5
branch n/a
condition n/a
subroutine 27 27 100.0
pod n/a
total 106 108 98.1


line stmt bran cond sub pod time code
1             package WebService::Braintree;
2             $WebService::Braintree::VERSION = '0.93';
3 1     1   79384 use strict;
  1         4  
  1         41  
4 1     1   9 use warnings;
  1         2  
  1         47  
5 1     1   387 use WebService::Braintree::Address;
  1         6  
  1         66  
6 1     1   641 use WebService::Braintree::AdvancedSearchFields;
  1         6  
  1         49  
7 1     1   570 use WebService::Braintree::AdvancedSearchNodes;
  1         4  
  1         42  
8 1     1   430 use WebService::Braintree::ApplePayCard;
  1         5  
  1         60  
9 1     1   590 use WebService::Braintree::CreditCard;
  1         6  
  1         54  
10 1     1   539 use WebService::Braintree::Customer;
  1         5  
  1         50  
11 1     1   738 use WebService::Braintree::CustomerSearch;
  1         5  
  1         57  
12 1     1   613 use WebService::Braintree::DisbursementDetails;
  1         7  
  1         55  
13 1     1   598 use WebService::Braintree::Dispute;
  1         6  
  1         56  
14 1     1   593 use WebService::Braintree::MerchantAccount;
  1         7  
  1         54  
15 1     1   515 use WebService::Braintree::PartnerMerchant;
  1         3  
  1         41  
16 1     1   9 use WebService::Braintree::PaymentMethod;
  1         2  
  1         22  
17 1     1   495 use WebService::Braintree::PayPalAccount;
  1         3  
  1         49  
18 1     1   506 use WebService::Braintree::PayPalDetails;
  1         6  
  1         45  
19 1     1   484 use WebService::Braintree::ResourceCollection;
  1         4  
  1         47  
20 1     1   466 use WebService::Braintree::SettlementBatchSummary;
  1         5  
  1         48  
21 1     1   512 use WebService::Braintree::Subscription;
  1         4  
  1         39  
22 1     1   550 use WebService::Braintree::SubscriptionSearch;
  1         4  
  1         42  
23 1     1   535 use WebService::Braintree::Transaction;
  1         7  
  1         67  
24 1     1   624 use WebService::Braintree::TransactionSearch;
  1         6  
  1         59  
25 1     1   593 use WebService::Braintree::Disbursement;
  1         6  
  1         51  
26 1     1   711 use WebService::Braintree::TransparentRedirect;
  1         3  
  1         36  
27 1     1   457 use WebService::Braintree::WebhookNotification;
  1         6  
  1         63  
28 1     1   617 use WebService::Braintree::WebhookTesting;
  1         6  
  1         54  
29 1     1   674 use WebService::Braintree::Configuration;
  0            
  0            
30              
31             =head1 NAME
32              
33             WebService::Braintree - A Client Library for wrapping the Braintree Payment
34             Services Gateway API
35              
36             =head2 FORK
37              
38             This is a fork of the original vendor-issued L<Net::Braintree>. While the
39             original is deprecated, it continues to work. However, it contains a number
40             of code-style and maintainability problems. This fork was produced to
41             address some of those problems and to provide a community driven basis for
42             going forward.
43              
44             =head2 DOCUMENTATION
45              
46             The module is sparsely documented, at best. The public facing API is very
47             similar to the Ruby libraries which are documented at
48             L<https://developers.braintreepayments.com/ruby/sdk/server/overview>.
49              
50              
51             You can also look over the test suite for guidance of usage, especially the
52             C<xt/sandbox> tests. Not all of these tests work (ones marked
53             C<todo_skip>. This is because they are an adaptation of code used against
54             Braintree's private integration server. Care has been taken that the same
55             sandbox tests that fail in this module also fail for L<Net::Braintree>, and
56             in the same manner.
57              
58             =head2 GENERAL STYLE
59              
60             In general, clients of this library will not instantiate any objects. Every
61             call you make will be a class method. Some methods will return objects. In
62             those cases, those objects will be documented for you.
63              
64             =cut
65              
66             my $configuration_instance = WebService::Braintree::Configuration->new;
67              
68             sub configuration { return $configuration_instance; }
69              
70             =head2 CONFIGURATION
71              
72             You will need to set some configuration.
73              
74             use WebService::Braintree;
75              
76             my $conf = WebService::Braintree->configuration;
77             $conf->environment( 'sandbox' );
78             $conf->merchant_id( 'use_your_merchant_id' );
79             $conf->public_key( 'use_your_public_key' );
80             $conf->private_key( 'use_your_private_key' );
81              
82             Please see L<WebService::Braintree::Configuration/> for more information.
83              
84             =head3 Client Tokens
85              
86             In general, your server code (that uses this library) will be interacting with
87             a client-side SDK (such as for Mobile or Javascript). That library will need a
88             client token in order to interact with Braintree. This token will be all the
89             client-side needs, regardless of whether your server is pointing at the sandbox
90             or to production.
91              
92             This token is created with L<WebService::Braintree::ClientToken/generate>.
93              
94             =head2 INTERFACE
95              
96             There are twelve classes that you will interface with. Please see their
97             respective documentation for more detail on how to use them.
98              
99             =head3 L<WebService::Braintree::Address>
100              
101             Create, update, delete, and find addresses.
102              
103             =head3 L<WebService::Braintree::ClientToken>
104              
105             Generate client tokens. These are used for client-side SDKs to take actions.
106              
107             =head3 L<WebService::Braintree::CreditCard>
108              
109             Create, update, delete, and find credit cards.
110              
111             =head3 L<WebService::Braintree::CreditCardVerification>
112              
113             Find and list credit card verifications.
114              
115             =head3 L<WebService::Braintree::Customer>
116              
117             Create, update, delete, and find customers.
118              
119             =head3 L<WebService::Braintree::MerchantAccount>
120              
121             Create, update, and find merchant accounts.
122              
123             =head3 L<WebService::Braintree::PaymentMethod>
124              
125             Create, update, delete, and find payment methods.
126              
127             =head3 L<WebService::Braintree::PayPalAccount>
128              
129             Find and update PayPal accounts.
130              
131             =head3 L<WebService::Braintree::SettlementBatchSummary>
132              
133             Generate settlement batch summaries.
134              
135             =head3 L<WebService::Braintree::Subscription>
136              
137             Create, update, cancel, find, and handle charges for subscriptions.
138              
139             =head3 L<WebService::Braintree::Transaction>
140              
141             Create, manage, and search for transactions. This is the workhorse class and it
142             has many methods.
143              
144             =head3 L<WebService::Braintree::TransparentRedirect>
145              
146             Manage the transparent redirection of ????.
147              
148             B<NOTE>: This class needs significant help in documentation.
149              
150             =head2 SEARCHING
151              
152             Several of the class interfaces provide a C<< search() >> method. This method
153             is unique in that it takes a subroutine reference (subref) instead of a hashref
154             or other parameters.
155              
156             Documentation for this is forthcoming.
157              
158             =head2 ISSUES
159              
160             The bugtracker is at
161             L<https://github.com/singingfish/braintree_perl/issues>.
162              
163             Patches welcome!
164              
165             =head2 CONTRIBUTING
166              
167             Contributions are welcome. The process:
168              
169             =over 4
170              
171             =item Submissions
172              
173             Please fork this repository on Github, create a branch, then submit a pull
174             request from that branch to the master of this repository. All other
175             submissions will be summarily rejected.
176              
177             =item Developer Environment
178              
179             We use Docker to encapsulate the developer environment. There is a Bash script
180             in the root called C<< run_tests >> that provides an entrypoint to how this
181             project uses Docker. The sequence is:
182              
183             =over 4
184              
185             =item run_tests build [ command ]
186              
187             =item run_tests test [ command ]
188              
189             =item run_tests integration [ command ]
190              
191             =item run_tests cover
192              
193             =back
194              
195             You can optionally select a Perl version or versions (5.10 through 5.24) to
196             run the command against by setting the C<< PERL_VERSIONS >> environment
197             variable. Use a space to separate multiple versions.
198              
199             This Bash script has been tested to work in Linux, OSX, and GitBash on Windows.
200              
201             =item Running the tests in xt/
202              
203             The tests in C<< t/ >> are unit tests. The tests in C<< xt/ >> are E2E tests
204             that run against Braintree's sandbox / integration environment. To run them,
205             you will need to have a Braintree sandbox account linked to Paypal.
206              
207             =over 4
208              
209             =item Signup
210              
211             Navigate to L<https://www.braintreepayments.com/sandbox>. Enter your first name,
212             last name, Comany name of "WebService::Braintree", your country, and your email
213             address.
214              
215             =item Activate your account
216              
217             You will receive an email to the address you provided which will contain a link.
218             Click on it and you'll sent to a page where you will be asked for a password.
219              
220             =item Create a sandbox_config.json
221              
222             On the dashboard page of your new sandbox account, three are three values you
223             will need to put into a C<< sandbox_config.json >>. The format of the file must
224             be:
225              
226             {
227             "merchant_id": "<< value 1 >>",
228             "public_key": "<< value 2 >>",
229             "private_key": "<< value 3 >>"
230             }
231              
232             replacing what's in the double-quotes with the appropriate values from your
233             Braintree sandbox's dashboard.
234              
235             =item Link your Paypal Sandbox Account
236              
237             You'll need to follow the instructions at L<< https://developers.braintreepayments.com/guides/paypal/testing-go-live/ruby#linked-paypal-testing >>. This is
238             required for some of the integration tests to pass.
239              
240             Within Setting > Processing, select "Link your sandbox" within the PayPal
241             section.
242              
243             Once at the Paypal Developer Dashboard:
244              
245             =over 4
246              
247             =item * My Apps & Credentials
248              
249             =item * Rest Apps
250              
251             =item * Create new App
252              
253             =item * Give it a name
254              
255             =item * Copy the information requested back to Braintree
256              
257             =back
258              
259             =item Run the tests
260              
261             You can now run the integration tests with C<< run_tests integration >>. These
262             tests will take between 5 and 20 minutes.
263              
264             =back
265              
266             =back
267              
268             =head2 TODO/WISHLIST/ROADMAP
269              
270             =over 4
271              
272             =item There is no pod documentation.
273              
274             =item Sandbox tests fail
275              
276             Some of this is likely needed because the sandbox account needs to be set
277             up just right, and some may be because the paypal test integration server
278             is emulating stateful transactions.
279              
280             =item Excessive metaobject wrangling
281              
282             The usage of L<Moose> in this code is sub-opimtimal. In particular the
283             following classes use the metaobject in a way that makes what is happening
284             difficult to understand:
285              
286             =over 4
287              
288             =item L<WebService::Braintree::ResultObject>
289              
290             This class is now the only one that is not immutable in the codebase.
291             Unpicking how to make this mutable is problematic.
292              
293             The constructors for the following should be fixed to be explicit (requires
294             understanding of what ResultObject is doing):
295              
296             =item L<WebService::Braintree::AdvancedSearchFields>
297              
298             =item L<WebService::Braintree::SubscriptionSearch>
299              
300             =item L<WebService::Braintree::CreditCardVerificationSearch>
301              
302             =item L<WebService::Braintree::CustomerSearch>
303              
304             =item L<WebService::Braintree::Result>
305              
306             =item L<WebService::Braintree::TransactionSearch>
307              
308             =back
309              
310             Also, having stared at the internals of some objects in the perl debugger
311             for a bit, I fear there may be memory leaks, but I have not investigated
312             this closely. It's also possible that the way that several of the above
313             methods use a C<$field> variable in package lexical scope that this module
314             may not be fork-safe. These concerns also apply to L<Net::Braintree> (only
315             it has a bigger memory footprint).
316              
317             =item Sandbox tests
318              
319             One of the sandbox tests is really really slow.
320              
321             =back
322              
323             =head2 ACKNOWLEDGEMENTS
324              
325             Thanks to the staff at Braintree for endorsing this fork.
326              
327             =head2 LICENSE AND COPYRIGHT
328              
329             Copyright 2017 Kieren Diment <zarquon@cpan.org>
330              
331             Copyright 2011-2014 Braintree, a division of PayPal, Inc.
332              
333             This program is free software; you can redistribute it and/or modify it
334             under the terms of either: the GNU General Public License as published
335             by the Free Software Foundation; or the Artistic License.
336              
337             See http://dev.perl.org/licenses/ for more information.
338              
339              
340             =cut
341              
342             1; # End of WebService::Braintree
343             __END__