NAME

Business::Stripe - Interface for Stripe payment system.

SYNOPSIS

my $stripe = StripeLite->new(
   -api_key => 'c6EiNIusHip8x5hkdIjtur7KNUA3TTpE'
);

$stripe->charges_create(
    amount => 400,
    card => 'tok_5EuIyKyCTc0f2V',
    description => 'Ice cream'
) and return $stripe->success;

print $stripe->error->{message}, "\n";

DESCRIPTION

Provides common bindings for Stripe payment system. Any API calls that do not have bindings can be access through the generic api method.

Public methods

new ({options})

Requires -api_key given to you as part of your Stripe account. Optional -url can override default:

https://api.stripe.com/v1/

api (method,path,params,...)

Generic function that sends requests to Stripe. Check Stripe's API documentation for specific calls.

Create a token:

$stripe->api('post', 'tokens', 
    'card[number]' => '4242424242424242',
    'card[exp_month]' => 12,
    'card[exp_year]' => 2012,
    'card[cvc]' => 123,
    'currency' => 'usd'
);

List charges:

$stripe->api('get', 'charges', count => 5, offset => 0);

Delete coupon:

$stripe->api('delete', 'coupons', '25OFF');

parameters

method

One of post, get, or delete.

path

Either charges, events, etc. Check API doc for complete list.

params

This optional set of parameters can be a single element or a list of key/value pairs.

All actions can be performed by using only this method. The two set of functions charges and customers provided in this package is available for functions that are used heavily by most programs.

error (void)

Methods returns 0 when encounter error conditions. The JSON object returned by Stripe can be retrieved via this method.

print $stripe->error->{message}, "\n";

success (void)

When calls are successful a positive value is returned or if possible, the ID. Stripe's JSON object can be retrieved via this method. Specific values are defined in the Stripe API Documentation.

print $stripe->success->{data}->[0]->{description}, "\n";

Charges

charges_create ({params})

Charge the credit card.

parameters

Assumes, currency is in usd. Uses token from Stripe.js.

$stripe->charges(
   amount => 10,
   card => 'tok_Wzm6ewTBrkVvC3',
   description => 'customer@example.com'
);
amount

Positive integer larger than .5.

currency

3-letter ISO code. Defaults to usd (it's the only one supported).

customer

Required if not using card below. The ID of an exisiting customer.

card

Required if not using customer above. Uses Token acquired from Stripe.js or give it the card details.

description (optional)

Descriptive text identifying the charge (recommend using customer's email).

returns

Returns the id if success (check result for JSON object). If error (use error for JSON object) returns undef.

charges_retrieve (id)

Takes the id value returned by successful this method yields data about the charge.

$stripe->charges_retrieve('ch_uxLBSIZB8azrSr');

charges_refund (id,[amount])

Refund an amount (or if omitted, full refund) to the charge id. amount is in cents.

### refunds full amount
$stripe->charges_refund('ch_uxLBSIZB8azrSr');

### refunds $5 over charge
$stripe->charges_refund('ch_uxLBSIZB8azrSr', 500);

charges_list ({params})

List all the charges for a particular customer or list everything.

### lists next 5 charges
$stripe->charges_list(count => 5, offset => 1);

parameters

count

Optional number of records to return. Defaults to 10.

offset

Optional paging marker. Defaults to 0.

customer

Optional customer's ID for filtering.

### list top 10 charges for this customer
$stripe->charges_list(customer => 'cus_gpj0mzwbQKBI7c');

Customers

customers_create ({params})

Creates a new customer according to the credit card information or token given. Use this method to create a customer-ID for the given card (token when used in conjunction with Stripe.js). The customer-ID can be passed to charges_create's customer parameter instead of card so that you don't have to ask for credit card info again.

### creates the customer
my $cid = $stripe->customers_create(
   card => 'tok_Wzm6ewTBrkVvC3',
   email => 'customer@example.com',
   description => 'userid-123456'
);

### charges the customer $5
$cid and $stripe->charges_create(
   customer => $cid,
   amount => 500,
   description => 'userid-123456 paid $5'
);

options

card

Can either be a token or credit card info.

coupon

Optional discount coupon code discount.

email

Optional customer's email.

description

Optional description.

returns

Returns customer's ID if succeeded.

customers_retrieve (id)

Gets the customer's object.

$stripe->customers_retrieve('cus_gpj0mzwbQKBI7c');

customers_update (id,[{params}])

Updates customer's information.

$stripe->customers_update(
   customer => 'cus_gpj0mzwbQKBI7c',
   description => 'updated description'
);

customers_delete (id)

Deletes the customer.

$stripe->customers_delete('cus_gpj0mzwbQKBI7c');

customers_list ({params})

List all customers.

$stripe->customers_list(count => 20);

parameters

count

Optional number of records to return. Defaults to 10.

offset

Optional paging marker. Defaults to 0.

Helper methods

_init (void)

Initializes the package and sets default values.

_compose (resource,[{params}])

Helper function takes in a resource, defined by the Stripe API doc. Current resources:

charges
coupons
customers
invoices
invoiceitems
plans
tokens
events

HISTORY

20120327

v0.01 Initial release

AUTHOR

Paul Pham (@phamnp)

COPYRIGHT AND LICENSE

Copyright (C) 2012 Paul Pham. All Rights Reserved.

This program and library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.