File Coverage

lib/WebService/Braintree.pm
Criterion Covered Total %
statement 81 83 97.5
branch n/a
condition n/a
subroutine 28 28 100.0
pod n/a
total 109 111 98.2


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