WebService::Stripe - Stripe API bindings
version 1.0300
my $stripe = WebService::Stripe->new( api_key => 'secret', version => '2014-11-05', # optional ); my $customer = $stripe->get_customer('cus_57eDUiS93cycyH');
Set the PERL_STRIPE_TEST_API_KEY environment variable to your Stripe test secret, then run tests as you normally would using prove.
WebService::Stripe supports passing custom headers to any API request by passing a hash of header values as the optional headers named parameter:
headers
$stripe->create_charge({ ... }, headers => { stripe_account => "acct_123" })
Note that header names are normalized: foo_bar, Foo-Bar, and foo-bar are equivalent.
foo_bar
Foo-Bar
foo-bar
Three headers stand out in particular:
This indicates the version of the Stripe API to use. If not given, we default to 2014-11-05, which is the earliest version of the Stripe API to support marketplaces.
2014-11-05
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.
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.
This feature is in ALPHA and subject to change without notice. Contact Stripe to confirm the latest behavior and header name.
get_customer($id)
Returns the customer for the given id.
create_customer($data)
Creates a customer. The $data hashref is optional. Returns the customer.
$data
Example:
$customer = $stripe->create_customer({ email => 'bob@foo.com' });
update_customer($id, data => $data)
Updates a customer. Returns the updated customer.
$customer = $stripe->update_customer($id, data => { description => 'foo' });
get_customers(query => $query)
Returns a list of customers. The query param is optional.
next($collection)
Returns the next page of results for the given collection.
my $customers = $stripe->get_customers; ... while ($customers = $stripe->next($customers)) { ... }
create_recipient($data)
Creates a recipient. The $data hashref is required and must contain at least name and type (which can be individual or corporate as per Stripe's documentation), but can contain more (see Stripe Docs). Returns the recipient.
name
type
individual
corporate
$recipient = $stripe->create_recipient({ name => 'John Doe', type => 'individual, });
get_recipient($id)
Retrieves a recipient by id. Returns the recipient.
$recipient = $stripe->get_recipient('rcp_123');
create_card($data, customer_id => 'cus_123')
get_charge($id, query => { expand => ['customer'] })
Returns the charge for the given id. The optional :$query parameter allows passing query arguments. Passing an arrayref as a query param value will expand it into Stripe's expected array format.
create_charge($data)
Creates a charge.
capture_charge($id, data => $data)
Captures the charge with the given id. The data param is optional.
refund_charge($id, data => $data)
Refunds the charge with the given id. The data param is optional.
refund_app_fee($fee_id, data => $data)
Refunds the application fee with the given id. The data param is optional.
update_charge($id, data => $data)
Updates an existing charge object.
add_source($cust_id, $card_data)
Adds a new funding source (credit card) to an existing customer.
get_token($id)
create_token($data)
get_account($id)
create_account($data)
update_account($id, data => $data)
get_platform_account($id)
Uploads a photo ID to an account.
my $account = $stripe->create_account({ managed => 'true', country => 'CA', }); my $file = $stripe->upload_identity_document( $account, '/tmp/photo.png' ); $stripe->update_account( $account->{id}, data => { legal_entity[verification][document] => $file->{id}, });
add_bank($data, account_id => $account_id)
Add a bank to an account.
my $account = $stripe->create_account({ managed => 'true', country => 'CA', }); my $bank = $stripe->add_bank( { 'bank_account[country]' => 'CA', 'bank_account[currency]' => 'cad', 'bank_account[routing_number]' => '00022-001', 'bank_account[account_number]' => '000123456789', }, account_id => $account->{id}, ); # or add a tokenised bank my $bank_token = $stripe->create_token({ 'bank_account[country]' => 'CA', 'bank_account[currency]' => 'cad', 'bank_account[routing_number]' => '00022-001', 'bank_account[account_number]' => '000123456789', }); $stripe->add_bank( { bank_account => $bank_token->{id} }, account_id => $account->{id}, );
update_bank($id, account_id => $account_id, data => $data)
create_transfer($data)
get_transfer($id)
get_transfers(query => $query)
update_transfer($id, data => $data)
cancel_transfer($id)
Reverses an existing transfer.
Stripe Documentation
$ws_stripe->reverse_transfer( # Transfer ID (required) $xfer_id, data => { # POST data (optional) refund_application_fee => 'true', amount => 100, description => 'Invoice Correction', 'metadata[local_reversal_id]' => 'rvrsl_123', 'metadata[requester]' => 'John Doe' }, headers => { # Headers (optional) stripe_account => $account->{'id'} } );
get_balance()
get_bitcoin_receivers()
create_bitcoin_receiver($data)
my $receiver = $stripe->create_bitcoin_receiver({ amount => 100, currency => 'usd', email => 'bob@tilt.com', });
get_bitcoin_receiver($id)
get_event($id)
Returns an event for the given id.
get_events(query => $query)
Returns a list of events. The query param is optional.
create_access_token($data)
Creates an access token for the Stripe Connect oauth flow https://stripe.com/docs/connect/reference#post-token
Naveed Massjouni <naveed@vt.edu>
Dan Schmidt <danschmidt5189@gmail.com>
Chris Behrens <chris@tilt.com>
This software is copyright (c) 2014 by Tilt, Inc.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install WebService::Stripe, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WebService::Stripe
CPAN shell
perl -MCPAN -e shell install WebService::Stripe
For more information on module installation, please visit the detailed CPAN module installation guide.