Ejemplo n.º 1
0
<?php 
// Require the Chargify.php file.
require_once 'Chargify-PHP-Client/lib/Chargify.php';
/**
 * Create a ChargifyProduct object in test mode.
 */
$test = TRUE;
$product = new ChargifyProduct(NULL, $test);
/**
 * Get details about all products available through your Chargify site.
 */
$products = $product->getAllProducts();
echo '<h2>Array of all product objects</h2>';
print_r($products);
/**
 * Get the first product based by ID. Will fail if there are no products.
 */
$product_x = new ChargifyProduct(NULL, $test);
$product_x->id = $products[0]->id;
echo '<h2>Single product object by ID</h2>';
print_r($product_x->getByID());
/**
 * Get the first product based by handle. Will fail if there are no products.
 */
$product_y = new ChargifyProduct(NULL, $test);
$product_y->handle = $products[0]->handle;
echo '<h2>Single product object by handle</h2>';
print_r($product_y->getByHandle());
?>
  </body>
</html>
Ejemplo n.º 2
0
// Create a card to go with the customer.
$card = new ChargifyCreditCard(NULL, $test);
$card->first_name = "Jane";
$card->last_name = "Smith";
// 1 is used in test mode for a vald credit card.
$card->full_number = '1';
$card->cvv = '123';
$card->expiration_month = "02";
$card->expiration_year = "2011";
$card->billing_address = "123 any st";
$card->billing_city = "Anytown";
$card->billing_state = "CA";
$card->billing_zip = "55555";
$card->billing_country = 'US';
// Get a list of products. The first one will be used.
$product = new ChargifyProduct(NULL, $test);
$products = $product->getAllProducts();
// Build subscription.
$subscription = new ChargifySubscription(NULL, $test);
$subscription->customer_attributes = $customer;
$subscription->credit_card_attributes = $card;
// Uses the first exising product. Replace with a product handle string.
$subscription->product_handle = $products[0]->handle;
echo '<h2>Cancel a new subscription</h2>';
try {
    // Save a new subscription.
    $new_subscription = $subscription->create();
    try {
        // Delete the newly saved subscription with a message.
        $deleted_subscription = $new_subscription->cancel('Subscription canceled');
        var_dump($deleted_subscription);