Skip to content

Instantly share code, notes, and snippets.

1. Under the main account:
- Create a token using the card details
- Turn the token into a customer
2. Once you've done that, under the sub-account:
- Create a token, passing the customer ID from step 1 as the "customer" argument
- Create a customer or charge using the token
$customer = Stripe_Customer::retrieve('cus_123');
$customer->card = $_POST['stripeToken'];
try {
$customer->save();
echo 'Card successfully updated!';
} catch (Stripe_CardError $e) {
echo 'Card declined. Please try again';
}
<input type="text" id="cc_exp" />
<input type="hidden" id="exp_month" data-stripe="exp_month" />
<input type="hidden" id="exp_year" data-stripe="exp_year" />
<?php
require 'path-to-Stripe.php';
if ($_POST) {
Stripe::setApiKey("YOUR-API-KEY");
$error = '';
$success = '';
try {
if (!isset($_POST['stripeToken']))
throw new Exception("The Stripe Token was not generated correctly");
def all_customers(args={}, count=50, offset=0)
rsp = Stripe::Customer.all(args.merge(:count => count, :offset => offset * count))
customers = rsp.data
if count * offset < rsp.count
customers += all_customers(args, count, offset + 1)
end
customers
end
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Stripe Getting Started Form</title>
<!-- The required Stripe lib -->
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<!-- jQuery is used only for this example; it isn't required to use Stripe -->
Stripe.setPublishableKey('pk_test_Wfzrj4uDDPOcv7XxVJKXRERS');
var l = Ladda.create( document.querySelector( '#addservice-submit' ) );
var stripeResponseHandler = function(status, response) {
if (response.error) {
// show the errors on the form
$("#stripe-errors").html(response.error.message);
} else {
var token = response['id'];
var form$ = $("#addservice-form");
require 'csv'
require 'stripe'
Stripe.api_key = "YOUR_SECRET_KEY"
CSV.load(File.open("customers.csv"), :headers => true).each do |row|
customer = Stripe::Customer.create(:description => row['description'], :email => row['email'])
puts "Created customer with ID: #{customer.id}"
end
You have just received a payment of $1.00.
You can view the full details of this payment in your dashboard:
https://manage.stripe.com/payments/ch_0usS6slsSbLaWA
Yours,
The Stripe team
{"customers":
[
{"1": "cus_1UNrOrybx3Q0WT"},
{"2": "cus_0rUF9n0itIh8xs"},
{"3": "cus_0ZEtHHmzDnteeJ"}
]
}