示例#1
0
require_once 'constants.php';
// Build the client using some custom configuration values.
$client = new Google_Client($GOOGLE_CLIENT_CONFIG);
$client->setApplicationName("Rapid Reseller - Transfer Token Demo (PHP)");
$client->setScopes($SETTINGS['OAUTH2_SCOPES']);
// Authenticate the client.
$client->setAssertionCredentials(new Google_AssertionCredentials($SETTINGS['OAUTH2_SERVICE_ACCOUNT_EMAIL'], $SETTINGS['OAUTH2_SCOPES'], file_get_contents($SETTINGS['OAUTH2_PRIVATE_KEY']), 'notasecret', 'http://oauth.net/grant_type/jwt/1.0/bearer', $SETTINGS['RESELLER_ADMIN']));
// This is ugly, but the client ID must be set here.
$client->setClientId($SETTINGS['OAUTH2_CLIENT_ID']);
// A service object takes a constructed and authenticated client.
$service = new Google_ResellerService($client);
// Create a new subscription object.
$subscription = new Google_Subscription();
$subscription->setCustomerId($_POST['customerDomain']);
$subscription->setSubscriptionId('123');
$subscription->setSkuId(ResellerSKU::GoogleApps);
$subscription->setPurchaseOrderId("mypurchaseorder-123");
// Subscriptions have a plan.
// Note: It is not possible to transfer a premier customer to a trial.
$plan = new Google_SubscriptionPlan();
$plan->setPlanName(ResellerPlanName::FLEXIBLE);
$plan->setIsCommitmentPlan(FALSE);
// Only annual subscription plans have a commitment interval.
// The following lines are commented out for reference.
/*
    $interval = new Google_SubscriptionPlanCommitmentInterval();
    $interval->setStartTime(time());
    $interval->setEndTime(time() + (86400 * 365));
    $plan->setCommitmentInterval($interval);
*/
$subscription->setPlan($plan);