Closed KatieP closed 11 years ago
//* This is about making the URL for update billing details*// Kori Francis, Jul 10 09:49 am (EDT): Katie,
The first number is the subscription ID, the second (the token) is detailed here: http://docs.chargify.com/hosted-page-integration (under Generating Tokens).
Essentially, it's the following: token = SHA1("update_payment--77--1234")[0..9] 77 is where the subscriptionID should be and 1234 is where the site's shared key should be (from here: https://green-pages.chargify.com/settings#hosted-page-urls - which is currently OG6AQ4YsCTh2lRfEP6p3)
So, taking the example and breaking it down - the token would be constructed like this:
token = SHA1("update_payment--3364787--OG6AQ4YsCTh2lRfEP6p3")[0..9] token = "7d83ff654785e8d25020960374bbf952441d7911"[0..9] token = "7d83ff6547"
-- Kori (@djbyter)
<?php
// token = SHA1("update_payment--3364787--OG6AQ4YsCTh2lRfEP6p3")[0..9]
// string sha1 ( string $str [, bool $raw_output = false ] )
// Site Shared Key: OG6AQ4YsCTh2lRfEP6p3
$token = sha1 ("update_payment--3364787--OG6AQ4YsCTh2lRfEP6p3");
$token_10 = substr($token, 0, 10); // returns "abcde"
echo $token_10;
?>
/* CHARGIFY API COMMUNICATION ---------------------------------------------------------------------------------*/
$chargify_key = '3FAaEvUO_ksasbblajon';
$chargify_auth = $chargify_key .':x';
$chargify_auth_url = 'https://'. $chargify_auth .'green-pages.chargify.com/subscriptions/';
echo PHP_EOL;
$chargify_url = 'https://green-pages.chargify.com/subscriptions/' . $subscription_id . '/components/' . $component_id . '/usages.json';
echo '$chargify_url: '. $chargify_url;
echo PHP_EOL;
echo 'Sending data to chargify ...';
echo PHP_EOL;
// Chargify api key: 3FAaEvUO_ksasbblajon
// http://docs.chargify.com/api-authentication
$ch = curl_init($chargify_auth_url);
$array = array();
array_push($array, 'Content-Type: application/json;', 'Accept: application/json;', 'charset=utf-8;');
curl_setopt($ch, CURLOPT_HTTPHEADER, $array);
curl_setopt($ch, CURLOPT_URL, $chargify_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
#curl_setopt($ch, CURLOPT_POSTFIELDS, $usage);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_USERPWD, $chargify_auth);
$result = curl_exec($ch);
echo $result;
echo PHP_EOL;
curl_close($ch);