File Coverage

blib/lib/WebService/Stripe.pm
Criterion Covered Total %
statement 45 363 12.4
branch 0 254 0.0
condition 0 131 0.0
subroutine 34 62 54.8
pod n/a
total 79 810 9.7


line stmt bran cond sub pod time code
1             package WebService::Stripe;
2 7     7   408815 use Moo;
  7         67958  
  7         35  
3             with 'WebService::Client';
4              
5             our $VERSION = '0.0800'; # VERSION
6              
7 7     7   9113 use Carp qw(croak);
  7         14  
  7         348  
8 7     7   4191 use Method::Signatures;
  7         368336  
  7         45  
9 7     7   3043 use constant { MARKETPLACES_MIN_VERSION => '2014-11-05' };
  7         11  
  7         876  
10              
11             has api_key => (
12             is => 'ro',
13             required => 1,
14             );
15              
16             has version => (
17             is => 'ro',
18             default => MARKETPLACES_MIN_VERSION,
19             );
20              
21             has '+base_url' => ( default => 'https://api.stripe.com' );
22              
23             has '+content_type' => ( default => 'application/x-www-form-urlencoded' );
24              
25 7     7   738585 method BUILD(@args) {
  1     1   2856  
  1         5  
26 1         4 $self->ua->default_headers->authorization_basic( $self->api_key, '' );
27 1         3565 $self->ua->default_header( 'Stripe-Version' => $self->version );
28             }
29              
30 7 0 0 7   24199 method next(HashRef $thing, HashRef :$query) {
  0 0 0 0      
  0 0 0        
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
31 0   0       $query ||= {};
32 0 0         return undef unless $thing->{has_more};
33 0 0         my $starting_after = $thing->{data}[-1]{id} or return undef;
34 0           return $self->get( $thing->{url},
35             { %$query, starting_after => $starting_after } );
36             }
37              
38 7 0 0 7   26906 method create_customer(Maybe[HashRef] $data, :$headers) {
  0 0   0      
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
39 0           return $self->post( "/v1/customers", $data, headers => $headers );
40             }
41              
42 7 0   7   14482 method get_balance(:$headers) {
  0 0   0      
  0            
  0            
  0            
  0            
  0            
43 0           return $self->get( "/v1/balance", {}, headers => $headers );
44             }
45              
46 7 0 0 7   19267 method get_customer(Str $id, :$headers) {
  0 0   0      
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
47 0           return $self->get( "/v1/customers/$id", {}, headers => $headers );
48             }
49              
50 7 0 0 7   25601 method update_customer(Str $id, HashRef $data, :$headers) {
  0 0 0 0      
  0 0          
  0 0          
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
  0            
51 0           return $self->post( "/v1/customers/$id", $data, headers => $headers );
52             }
53              
54 7 0 0 7   23357 method get_customers(HashRef :$query, :$headers) {
  0 0 0 0      
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
  0            
55 0           return $self->get( "/v1/customers", $query, headers => $headers );
56             }
57              
58 7 0 0 7   27031 method create_card(HashRef $data, :$customer_id!, :$headers) {
  0 0   0      
  0 0          
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
59 0           return $self->post(
60             "/v1/customers/$customer_id/cards", $data, headers => $headers );
61             }
62              
63 7 0 0 7   21814 method get_charge(Str $id, :$headers) {
  0 0   0      
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
64 0           return $self->get( "/v1/charges/$id", {}, headers => $headers );
65             }
66              
67 7 0 0 7   21498 method create_charge(HashRef $data, :$headers) {
  0 0   0      
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
68 0           return $self->post( "/v1/charges", $data, headers => $headers );
69             }
70              
71 7 0 0 7   26331 method capture_charge(Str $id, HashRef :$data, :$headers) {
  0 0 0 0      
  0 0 0        
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
72 0           return $self->post( "/v1/charges/$id/capture", $data, headers => $headers );
73             }
74              
75 7 0 0 7   29540 method refund_charge(Str $id, HashRef :$data, :$headers) {
  0 0 0 0      
  0 0 0        
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
76 0           return $self->post( "/v1/charges/$id/refunds", $data, headers => $headers );
77             }
78              
79 7 0 0 7   23810 method create_token(HashRef $data, :$headers) {
  0 0   0      
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
80 0           return $self->post( "/v1/tokens", $data, headers => $headers );
81             }
82              
83 7 0 0 7   21069 method get_token(Str $id, :$headers) {
  0 0   0      
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
84 0           return $self->get( "/v1/tokens/$id", {}, headers => $headers );
85             }
86              
87 7 0 0 7   20673 method create_account(HashRef $data, :$headers) {
  0 0   0      
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
88 0           return $self->post( "/v1/accounts", $data, headers => $headers );
89             }
90              
91 7 0 0 7   19503 method get_account(Str $id, :$headers) {
  0 0   0      
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
92 0           return $self->get( "/v1/accounts/$id", {}, headers => $headers );
93             }
94              
95 7 0 0 7   27419 method update_account(Str $id, HashRef :$data!, :$headers) {
  0 0 0 0      
  0 0          
  0 0          
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
96 0           return $self->post( "/v1/accounts/$id", $data, headers => $headers );
97             }
98              
99 7 0 0 7   26838 method add_bank(HashRef $data, Str :$account_id!, :$headers) {
  0 0 0 0      
  0 0          
  0 0          
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
100 0           return $self->post(
101             "/v1/accounts/$account_id/bank_accounts", $data, headers => $headers );
102             }
103              
104 7 0 0 7   32757 method update_bank(Str $id, Str :$account_id!, HashRef :$data!, :$headers) {
  0 0 0 0      
  0 0 0        
  0 0          
  0 0          
  0 0          
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
105 0           return $self->post( "/v1/accounts/$account_id/bank_accounts/$id", $data,
106             headers => $headers );
107             }
108              
109 7 0 0 7   27857 method delete_bank(Str $id, Str :$account_id!, :$headers) {
  0 0 0 0      
  0 0          
  0 0          
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
110 0           return $self->delete(
111             "/v1/accounts/$account_id/bank_accounts/$id", headers => $headers );
112             }
113              
114 7 0 0 7   22371 method get_banks(Str :$account_id!, :$headers) {
  0 0   0      
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
  0            
115 0           return $self->get(
116             "/v1/accounts/$account_id/bank_accounts", {}, headers => $headers );
117             }
118              
119 7 0 0 7   19624 method create_transfer(HashRef $data, :$headers) {
  0 0   0      
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
120 0           return $self->post( "/v1/transfers", $data, headers => $headers );
121             }
122              
123 7 0 0 7   19683 method get_transfer(Str $id, :$headers) {
  0 0   0      
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
124 0           return $self->get( "/v1/transfers/$id", {}, headers => $headers );
125             }
126              
127 7 0 0 7   20434 method get_transfers(HashRef :$query, :$headers) {
  0 0 0 0      
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
  0            
128 0           return $self->get( "/v1/transfers", $query, headers => $headers );
129             }
130              
131 7 0 0 7   25576 method update_transfer(Str $id, HashRef :$data!, :$headers) {
  0 0 0 0      
  0 0          
  0 0          
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
  0            
  0            
132 0           return $self->post( "/v1/transfers/$id", $data, headers => $headers );
133             }
134              
135 7 0 0 7   20813 method cancel_transfer(Str $id, :$headers) {
  0 0   0      
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
136 0           return $self->post("/v1/transfers/$id/cancel", undef, headers => $headers);
137             }
138              
139 7 0 0 7   20376 method get_bitcoin_receivers(HashRef :$query, :$headers) {
  0 0 0 0      
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
  0            
140 0           return $self->get( "/v1/bitcoin/receivers", $query, headers => $headers );
141             }
142              
143 7 0 0 7   19311 method create_bitcoin_receiver(HashRef $data, :$headers) {
  0 0   0      
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
144 0           return $self->post( "/v1/bitcoin/receivers", $data, headers => $headers );
145             }
146              
147 7 0 0 7   19214 method get_bitcoin_receiver(Str $id, :$headers) {
  0 0   0      
  0 0          
  0 0          
  0            
  0            
  0            
  0            
  0            
  0            
148 0           return $self->get( "/v1/bitcoin/receivers/$id", {}, headers => $headers );
149             }
150              
151             # ABSTRACT: Stripe API bindings
152              
153              
154             1;
155              
156             __END__
157              
158             =pod
159              
160             =encoding UTF-8
161              
162             =head1 NAME
163              
164             WebService::Stripe - Stripe API bindings
165              
166             =head1 VERSION
167              
168             version 0.0800
169              
170             =head1 SYNOPSIS
171              
172             my $stripe = WebService::Stripe->new(
173             api_key => 'secret',
174             version => '2014-11-05', # optional
175             );
176             my $customer = $stripe->get_customer('cus_57eDUiS93cycyH');
177              
178             =head1 HEADERS
179              
180             WebService::Stripe supports passing custom headers to any API request by passing a hash of header values as the optional C<headers> named parameter:
181              
182             $stripe->create_charge({ ... }, headers => { stripe_account => "acct_123" })
183              
184             Note that header names are normalized: C<foo_bar>, C<Foo-Bar>, and C<foo-bar> are equivalent.
185              
186             Three headers stand out in particular:
187              
188             =over
189              
190             =item Stripe-Version
191              
192             This indicates the version of the Stripe API to use. If not given, we default to C<2014-11-05>, which is the earliest version of the Stripe API to support marketplaces.
193              
194             =item Stripe-Account
195              
196             This specifies the ID of the account on whom the request is being made. It orients the Stripe API around that account, which may limit what records or actions are able to be taken. For example, a `get_card` request will fail if given the ID of a card that was not associated with the account.
197              
198             =item Idempotency-Key
199              
200             All POST methods support idempotent requests through setting the value of an Idempotency-Key header. This is useful for preventing a request from being executed twice, e.g. preventing double-charges. If two requests are issued with the same key, only the first results in the creation of a resource; the second returns the latest version of the existing object.
201              
202             This feature is in ALPHA and subject to change without notice. Contact Stripe to confirm the latest behavior and header name.
203              
204             =back
205              
206             =head1 METHODS
207              
208             =head2 get_customer
209              
210             get_customer($id)
211              
212             Returns the customer for the given id.
213              
214             =head2 create_customer
215              
216             create_customer($data)
217              
218             Creates a customer.
219             The C<$data> hashref is optional.
220             Returns the customer.
221              
222             Example:
223              
224             $customer = $stripe->create_customer({ email => 'bob@foo.com' });
225              
226             =head2 update_customer
227              
228             update_customer($id, $data)
229              
230             Updates a customer.
231             Returns the updated customer.
232              
233             Example:
234              
235             $customer = $stripe->update_customer($id, { description => 'foo' });
236              
237             =head2 get_customers
238              
239             get_customers(query => $query)
240              
241             Returns a list of customers.
242             The query param is optional.
243              
244             =head2 next
245              
246             next($collection)
247              
248             Returns the next page of results for the given collection.
249              
250             Example:
251              
252             my $customers = $stripe->get_customers;
253             ...
254             while ($customers = $stripe->next($customers)) {
255             ...
256             }
257              
258             =head2 create_card
259              
260             create_card($data, customer_id => 'cus_123')
261              
262             =head2 get_charge
263              
264             get_charge($id)
265              
266             Returns the charge for the given id.
267              
268             =head2 create_charge
269              
270             create_charge($data)
271              
272             Creates a charge.
273              
274             =head2 capture_charge
275              
276             capture_charge($id, data => $data)
277              
278             Captures the charge with the given id.
279             The data param is optional.
280              
281             =head2 refund_charge
282              
283             refund_charge($id, data => $data)
284              
285             Refunds the charge with the given id.
286             The data param is optional.
287              
288             =head2 get_token
289              
290             get_token($id)
291              
292             =head2 create_token
293              
294             create_token($data)
295              
296             =head2 get_account
297              
298             get_account($id)
299              
300             =head2 create_account
301              
302             create_account($data)
303              
304             =head2 update_account
305              
306             update_account($id, data => $data)
307              
308             =head2 add_bank
309              
310             add_bank($data, account_id => $account_id)
311              
312             Add a bank to an account.
313              
314             Example:
315              
316             my $account = $stripe->create_account({
317             managed => 'true',
318             country => 'CA',
319             });
320              
321             my $bank = $stripe->add_bank(
322             {
323             'bank_account[country]' => 'CA',
324             'bank_account[currency]' => 'cad',
325             'bank_account[routing_number]' => '00022-001',
326             'bank_account[account_number]' => '000123456789',
327             },
328             account_id => $account->{id},
329             );
330              
331             # or add a tokenised bank
332              
333             my $bank_token = $stripe->create_token({
334             'bank_account[country]' => 'CA',
335             'bank_account[currency]' => 'cad',
336             'bank_account[routing_number]' => '00022-001',
337             'bank_account[account_number]' => '000123456789',
338             });
339              
340             $stripe->add_bank(
341             { bank_account => $bank_token->{id} },
342             account_id => $account->{id},
343             );
344              
345             =head2 update_bank
346              
347             update_bank($id, account_id => $account_id, data => $data)
348              
349             =head2 create_transfer
350              
351             create_transfer($data)
352              
353             =head2 get_transfer
354              
355             get_transfer($id)
356              
357             =head2 get_transfers
358              
359             get_transfers(query => $query)
360              
361             =head2 update_transfer
362              
363             update_transfer($id, data => $data)
364              
365             =head2 cancel_transfer
366              
367             cancel_transfer($id)
368              
369             =head2 get_balance
370              
371             get_balance()
372              
373             =head2 get_bitcoin_receivers
374              
375             get_bitcoin_receivers()
376              
377             =head2 create_bitcoin_receiver
378              
379             create_bitcoin_receiver($data)
380              
381             Example:
382              
383             my $receiver = $stripe->create_bitcoin_receiver({
384             amount => 100,
385             currency => 'usd',
386             email => 'bob@tilt.com',
387             });
388              
389             =head2 get_bitcoin_receiver
390              
391             get_bitcoin_receiver($id)
392              
393             =head1 AUTHORS
394              
395             =over 4
396              
397             =item *
398              
399             Naveed Massjouni <naveed@vt.edu>
400              
401             =item *
402              
403             Dan Schmidt <danschmidt5189@gmail.com>
404              
405             =back
406              
407             =head1 COPYRIGHT AND LICENSE
408              
409             This software is copyright (c) 2014 by Tilt, Inc.
410              
411             This is free software; you can redistribute it and/or modify it under
412             the same terms as the Perl 5 programming language system itself.
413              
414             =cut