Net::Stripe::Simple - simple, non-Moose interface to the Stripe API
use Net::Stripe::Simple; my $stripe = Net::Stripe::Simple->new('sk_test_00000000000000000000000000'); # when the only argument is an id, that's all you need my $c1 = $stripe->customers( retrieve => 'cus_meFAKEfakeFAKE' ); # you can provide arguments as a hash reference my $c2 = $stripe->customers( retrieve => { id => 'cus_ImFAKEfakeFAKE' } ); # or as key-value list my $c3 = $stripe->customers( 'retrieve', id => 'cus_I2FAKEfakeFAKE', expand => 1 );
A lightweight, limited-dependency client to the stripe.com API. This is just a thin wrapper around stripe's RESTful API. It is "simple" in the sense that it is simple to write and maintain and it maps simply onto Stripe's web documentation, so it is simple to use. When you get a response back, it's just the raw JSON blessed with some convenience methods: stringification to ids and autoloaded attributes (Net::Stripe::Simple::Data). If there is an error, the error that is thrown is again just Stripe's JSON with a little blessing (Net::Stripe::Simple::Error).
This simplicity comes at a cost: Net::Stripe::Simple does not validate your parameters aside from those required to construct the URL before constructing a request and sending it off to Stripe. This means that if you've done it wrong it takes a round trip to find out.
For the full details of stripe's API, see https://stripe.com/docs/api.
Following the organization scheme of Stripe's API, actions are grouped by entity type, each entity corresponding to a method. For a given method there are generally a number of actions, which are treated as the primary key in a parameter hash. Parameters for these actions are provided by a parameter hash which is the value of the primary key. However, there is some flexibility.
Methods that require only an id are flexible. All the following will work:
$stripe->plans( retrieve => { id => $id } ); $stripe->plans( 'retrieve', id => $id ); $stripe->plans( retrieve => $id );
Methods that require no arguments are also flexible:
$stripe->plans( list => { } ); $stripe->plans('list');
Net::Stripe::Simple exports nothing by default. It has four exportable constants and one exportable function:
To facilitate their export, it has two tags:
The three constants.
The three constants plus data_object.
data_object
Net::Stripe::Simple->('sk_test_00000000000000000000000000', '2014-01-31')
The class constructor method. The API key is required. The version date is optional. If not supplied, the value of $Net::Stripe::Simple::STRIPE_VERSION will be supplied. Net::Stripe::Simple was implemented or has been updated for the following versions:
$Net::Stripe::Simple::STRIPE_VERSION
The default version will always be the most recent version whose handling required an update to Net::Stripe::Simple.
See https://stripe.com/docs/api#charges.
Available Actions
$charge = $stripe->charges( create => { customer => $customer, amount => 100, currency => 'usd', capture => false, } );
$charge = $stripe->charges( retrieve => $id );
$charge = $stripe->charges( update => { id => $charge, description => 'foo', } );
Availability may depend on version of API. $charge = $stripe->charges( refund => $id );
$charge = $stripe->charges( capture => $id );
my $charges = $stripe->charges('list');
See https://stripe.com/docs/api#refunds.
my $refund = $stripe->refunds( create => { id => $charge, amount => 50 } );
$refund = $stripe->refunds( retrieve => { id => $refund, charge => $charge } );
$refund = $stripe->refunds( update => { id => $refund, charge => $charge, metadata => { foo => 'bar' } } );
my $refunds = $stripe->refunds( list => $charge );
See https://stripe.com/docs/api#customers.
$customer = $stripe->customers( create => { metadata => { foo => 'bar' } } );
$customer = $stripe->customers( retrieve => $id );
$customer = $stripe->customers( update => { id => $customer, metadata => { foo => 'baz' } } );
$customer = $stripe->customers( delete => $id );
my $customers = $stripe->customers( list => { created => { gte => $time - 100 } } );
See https://stripe.com/docs/api#cards.
$card = $stripe->cards( create => { customer => $customer, card => { number => '4242424242424242', exp_month => $expiry->month, exp_year => $expiry->year, cvc => 123 } } );
$card = $stripe->cards( retrieve => { customer => $customer, id => $id } );
$card = $stripe->cards( update => { customer => $customer, id => $card, name => 'foo', } );
$card = $stripe->cards( delete => { customer => $customer, id => $id } );
my $cards = $stripe->cards( list => $customer );
See https://stripe.com/docs/api#subscriptions.
$subscription = $stripe->subscriptions( create => { customer => $customer, plan => $plan, } );
$subscription = $stripe->subscriptions( retrieve => { id => $id, customer => $customer, } );
$subscription = $stripe->subscriptions( update => { id => $id, customer => $customer, metadata => { foo => 'bar' } } );
$subscription = $stripe->subscriptions( cancel => { id => $id, customer => $customer, } );
my $subscriptions = $stripe->subscriptions( list => $customer );
See https://stripe.com/docs/api#plans.
$plan = $stripe->plans( create => { id => $id, amount => 100, currency => 'usd', interval => 'week', name => 'Foo', } );
$plan = $stripe->plans( retrieve => $id );
$plan = $stripe->plans( update => { id => $id, metadata => { bar => 'baz' } } );
$plan = $stripe->plans( delete => $id );
my $plans = $stripe->plans('list');
See https://stripe.com/docs/api#coupons.
$coupon = $stripe->coupons( create => { percent_off => 1, duration => 'forever', } );
$coupon = $stripe->coupons( retrieve => $id );
$coupon = $stripe->coupons( delete => $coupon );
my $coupons = $stripe->coupons('list');
See https://stripe.com/docs/api#discounts.
my $deleted = $stripe->discounts( customer => $c );
$deleted = $stripe->discounts( subscription => { customer => $c, subscription => $s, } );
See https://stripe.com/docs/api#invoices.
my $new_invoice = $stripe->invoices( create => { customer => $customer, } );
$invoice = $stripe->invoices( retrieve => $id );
my $lines = $stripe->invoices( lines => $invoice );
$stripe->subscriptions( update => { customer => $customer, id => $subscription, plan => $spare_plan, } );
$new_invoice = $stripe->invoices( pay => $new_invoice );
my $invoices = $stripe->invoices( list => { customer => $customer } );
$new_invoice = $stripe->invoices( upcoming => $customer );
See https://stripe.com/docs/api#invoiceitems.
my $item = $stripe->invoice_items( create => { customer => $customer, amount => 100, currency => 'usd', metadata => { foo => 'bar' } } );
$item = $stripe->invoice_items( retrieve => $id );
$item = $stripe->invoice_items( update => { id => $item, metadata => { foo => 'baz' } } );
$item = $stripe->invoice_items( delete => $item );
my $items = $stripe->invoice_items( list => { customer => $customer } );
See https://stripe.com/docs/api#disputes.
$stripe->disputes( update => { id => $charge, metadata => { foo => 'bar' } } );
$stripe->disputes( close => $charge );
See https://stripe.com/docs/api/payment_intents.
$stripe->payment_intents( create => { amount => 100, currency => 'usd', customer => $customer, payment_method => $card, } );
$payment_intent = $stripe->payment_intents( retrieve => $id );
$stripe->payment_intents( list => { customer => $customer } );
$stripe->payment_intents( confirm => { id => $payment_intent, } );
$stripe->payment_intents( capture => { id => $payment_intent, } );
$payment_intent = $stripe->payment_intents( cancel => $payment_intent );
Transfers in Stripe no longer have the meaning that this module originally implemented (see https://stripe.com/docs/transfer-payout-split). As such, they have been removed from the module for the time being. They will be added in their new meaning with a suitable PR.
Recipients have been deprecated and are no longer available in the Stripe API, so have been removed from this module. They have been replaced by Custom accounts (see https://stripe.com/docs/connect/recipient-account-migrations).
See https://stripe.com/docs/api#application_fees.
my $fee = $stripe->application_fees( retrieve => $id );
my $fee = $stripe->application_fees( refund => $id );
my $fees = $stripe->application_fees('list');
See https://stripe.com/docs/api#account.
my $account = $stripe->account('retrieve'); # or $account = $stripe->account;
See https://stripe.com/docs/api#balance.
my $balance = $stripe->balance('retrieve');
my $history = $stripe->balance('history');
$balance = $stripe->balance( transaction => $charge );
See https://stripe.com/docs/api#events.
$event = $stripe->events( retrieve => $id );
my $events = $stripe->events( list => { created => { gt => $time } } );
See https://stripe.com/docs/api#tokens.
$token = $stripe->tokens( create => { card => { number => '4242424242424242', exp_month => $expiry->month, exp_year => $expiry->year, cvc => 123 } } ); $token = $stripe->tokens( create => { bank_account => { country => 'US', routing_number => '110000000', account_number => '000123456789', } } );
$token = $stripe->tokens( retrieve => $id );
To preserve the parallel with the Stripe's API documentation, there is a special "bank" action, but it is simply a synonym for the code above. $token = $stripe->tokens( bank => { bank_account => { country => 'US', routing_number => '110000000', account_number => '000123456789', } } );
This function recursively converts a hash ref into a data object. This is just Net::Stripe::Simple::Data, whose only function is to autoload accessors for all the keys in the hash. It is made for adding magic to JSON objects. If you try to give it something that contains blessed references whose class is outside the JSON namespace it will die.
Net::Stripe, Business::Stripe
These are just the corresponding JSON constants. They are exported by Net::Stripe::Simple for convenience.
use Net::Stripe::Simple qw(:const); ... my $subscription = $stripe->subscriptions( update => { id => $id, customer => $customer_id, plan => $plan_id, prorate => true, } );
You can import the constants individually or all together with :const.
:const
Andy Beverley <andy@andybev.com>
Grant Street Group <developers@grantstreet.com>
David F. Houghton <dfhoughton@gmail.com>
This software is copyright (c) 2014 by Grant Street Group.
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 Net::Stripe::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Stripe::Simple
CPAN shell
perl -MCPAN -e shell install Net::Stripe::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.