File Coverage

blib/lib/WebService/Braintree.pm
Criterion Covered Total %
statement 82 84 97.6
branch n/a
condition n/a
subroutine 28 28 100.0
pod n/a
total 110 112 98.2


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