Skip to content

Instantly share code, notes, and snippets.

@yazinsai
Last active August 29, 2015 14:12
Show Gist options
  • Save yazinsai/20993e22a7f257557115 to your computer and use it in GitHub Desktop.
Save yazinsai/20993e22a7f257557115 to your computer and use it in GitHub Desktop.
Create and charge a customer using pure PHP (for Alexey)
<?php
# Step 1: Create a customer from the card details
require_once("vendor/autoload.php");
White::setApiKey("test_sec_k_886a1e89b2c0abce479bf"); // Secret key
$customer = White_Customer::create(array(
'name' => "John Doe",
'description' => "Amember customer",
'email' => "john.doe@example.com",
'card' => array(
'number' => "4242424242424242",
'exp_month' => 12,
'exp_year' => 2015,
'cvc' => '123'
)
));
$id = $customer->id; // Store this for later billing
# Step 2: Bill at a later time
$charge = White_Charge::create(array(
"amount" => 1000, // = $10.00
"currency" => "USD",
"customer_id" => $id,
"description" => "Charge for monthly plan"
));
var_export($charge);
@yazinsai
Copy link
Author

A few things have changed with the release of the new API:

  1. When creating a token, we pass the open key in the Authentication Header and not as a parameter.
  2. The card parameter is no longer nested in the token request
  3. We use $customer->id instead of $customer->tag
  4. Charge amounts now use cents (or the smallest currency unit) instead of decimals. (e.g. amount=1000 is interpreted as $10.00)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment