Inheritance: extends Recurly_Resource
示例#1
0
 public function testCreateUsageFromSubscription()
 {
     $this->client->addResponse('GET', '/subscriptions/012345678901234567890123456789ab', 'subscriptions/show-200.xml');
     $this->client->addResponse('POST', '/subscriptions/012345678901234567890123456789ab/add_ons/marketing_emails/usage', 'usage/create-201.xml');
     $subscription = Recurly_Subscription::get('012345678901234567890123456789ab', $this->client);
     $usage = $subscription->buildUsage('marketing_emails', $this->client);
     $usage->create();
     $this->assertInstanceOf('Recurly_Usage', $usage);
     $this->assertInstanceOf('Recurly_Stub', $usage->measured_unit);
 }
 protected function uri()
 {
     if (!empty($this->_href)) {
         return $this->getHref();
     } else {
         if (!empty($this->uuid)) {
             return Recurly_Subscription::uriForSubscription($this->uuid);
         } else {
             throw new Recurly_Error("Subscription UUID not specified");
         }
     }
 }
 /**
  * Add new payment into database
  * 
  * @author coeus solutions
  * @param array $data the data from REST Client
  * @return \Zend\View\Model\JsonModel 
  */
 public function create($data = array())
 {
     try {
         $exist = $this->getService()->checkAlreadySubscribed($data['customer_id']);
         if (!$exist) {
             \Recurly_Client::$subdomain = 'incoverage123';
             \Recurly_Client::$apiKey = '1087e99b0df34eb4835412e55217dc6f';
             $account_code = uniqid();
             // Subscription
             $subscription = new \Recurly_Subscription();
             $subscription->plan_code = 'basic';
             $subscription->currency = 'USD';
             $account = new \Recurly_Account();
             //$subscription->account->account_code = 'john_rambo';
             $account->account_code = $account_code;
             $account->first_name = $data['first_name'];
             $account->last_name = $data['last_name'];
             $account->email = '*****@*****.**';
             $account->address->city = $data['city'];
             $account->address->state = $data['state'];
             $account->address->country = $data['country'];
             $account->address->zip = $data['postal_code'];
             $account->address->address1 = $data['address1'];
             $account->create();
             // Billing Infos
             $billing_info = new \Recurly_BillingInfo();
             $billing_info->account_code = $account_code;
             //$billing_info->first_name = $data['first_name'];
             //$billing_info->last_name = $data['last_name'];
             //$billing_info->number = $data['number'];
             //$billing_info->verification_value = '123';
             //$billing_info->month = $data['month'];
             //$billing_info->year = $data['year'];
             $billing_info->token_id = $data['token'];
             $account->billing_info = $billing_info;
             $subscription->account = $account;
             $subscription->create();
             $info = array('customerId' => $data['customer_id'], 'accountCode' => $account_code, 'planCode' => 'basic');
             $this->getService()->addPayment($info);
             /*// Adjustments
               $charge = new \Recurly_Adjustment();
               $charge->account_code = $account_code;
               $charge->description = 'Charge for extra bandwidth';
               $charge->unit_amount_in_cents = 5000; // $50.00
               $charge->currency = 'USD';
               $charge->quantity = 1;
               $charge->accounting_code = 'bandwidth';
               $charge->tax_exempt = false;
               $charge->create();*/
             //$billing_info->create();
         } else {
             $error = 'Already subscribed.';
         }
     } catch (\Recurly_NotFoundError $e) {
         $error = $e->getMessage();
     } catch (\Recurly_ValidationError $e) {
         // If there are multiple errors, they are comma delimited:
         //$messages = explode(',', $e->getMessage());
         //print 'Validation problems: ' . implode("\n", $messages);
         $error = $e->getMessage();
     } catch (\Recurly_ServerError $e) {
         $error = $e->getMessage();
     } catch (Exception $e) {
         // Assign the error message and use it to handle any customer
         // messages or logging
         $error = $e->getMessage();
     }
     if (isset($error)) {
         $result['data']['status'] = false;
         $result['data']['error'] = $error;
     } else {
         $result['data']['status'] = true;
     }
     return new JsonModel($result);
 }
示例#4
0
文件: aaa.php 项目: ram-1501/rs
                     $createdAt = strtotime($xmlResp->activated_at) . "000";
                     if ($paymentState == 'active') {
                         $api->setPaymentConfig($email, $pass, SERVER_IDENTIFIER, $paymentId, $accountCode, $paymentLicense, $paymentState, $createdAt);
                         $api->setUserLicense($email, SERVER_IDENTIFIER);
                         echo $alertMsg . $paymentLicense . '.';
                     }
                 } catch (Exception $e) {
                     echo $e->getMessage();
                     break;
                 }
             }
         } else {
             try {
                 $subscription = Recurly_Subscription::get($paymentId);
                 $subscription->cancel();
                 $subscription = Recurly_Subscription::get($paymentId);
                 if ($subscription->state == 'canceled') {
                     $api->updateUserPaymentConfig(SERVER_IDENTIFIER, $paymentLicense, $email, $subscription->state);
                     $api->setUserLicense($email, SERVER_IDENTIFIER);
                     echo $alertMsg . $paymentLicense . '.';
                 }
             } catch (Exception $e) {
                 echo $e->getMessage();
                 break;
             }
         }
     } else {
         echo "Error: Incorrect email or password.";
     }
     break;
 case "isLoggedIn":
 public function createSubscription($plan_code, $billing_on_file = NULL)
 {
     error_log("Createsub am called", 0);
     if ($plan_code != "daily") {
         try {
             error_log("*****attempting to create a subscription", 0);
             $subscription = new Recurly_Subscription();
             $subscription->plan_code = $plan_code;
             $subscription->currency = "USD";
             $subscription->account = $this->recurlyAccount;
             if ($billing_on_file) {
                 // use the billing info on file…don't change any billing info
             } else {
                 $subscription->account->billing_info = $this->billing_info;
             }
             $data["plan_code"] = $plan_code;
             $data["user_id"] = $this->account->id;
             $data["state"] = "active";
             $query = $this->db->query("select plan_code from subscription_sync where user_id='" . $this->account->id . "';");
             if ($query->num_rows() > 0) {
                 $this->db->where('user_id', $this->account->id);
                 error_log("updating subscription_sync", 0);
                 $queryresult = $this->db->update('subscription_sync', $data);
             } else {
                 error_log("inserting subscription_sync", 0);
                 $queryresult = $this->db->insert("subscription_sync", $data);
             }
             $subscription->create();
             $result = isset($subscription->uuid);
             error_log("*****Recurly subscription successfully created");
         } catch (Recurly_ValidationError $e) {
             error_log("*****" . $e->getMessage());
             $this->db->where('user_id', $this->account->id);
             $this->db->delete('subscription_sync');
             if ($e->getMessage() === "Subscriptions is invalid. Account Cannot create multiple subscriptions for same account.") {
                 $response = array("error" => 'ALREADY_HAS_SUB', "message" => $e->getMessage());
                 return $response;
             } else {
                 $response = array("error" => 'INVALID_CC', "message" => $e->getMessage());
                 return $response;
             }
         } catch (Recurly_Error $e) {
             error_log("*****" . $e->getMessage());
             $this->db->where('user_id', $this->account->id);
             $this->db->delete('subscription_sync');
             $response = array("error" => 'GATEWAY_ERROR', "message" => $e->getMessage());
             return $response;
         } catch (Exception $e) {
             error_log("*****" . $e->getMessage());
             $this->db->where('user_id', $this->account->id);
             $this->db->delete('subscription_sync');
             $response = array("error" => 'GRIND_EXCEPTION', "message" => $e->getMessage());
             return $response;
         }
     } else {
         // daily member
         //add billingdata to recurly!!!
         error_log("*****adding a daily member", 0);
         $this->recurlyAccount->billing_info = $this->billing_info;
         $this->recurlyAccount->update();
         $data["plan_code"] = $plan_code;
         $data["user_id"] = $this->account->id;
         $data["state"] = "active";
         $result = $this->db->insert("subscription_sync", $data);
     }
     return $result;
 }
 public function createRecurlySubscription2(Recurly_Account $account, $planCode, $billingFirstName, $billingLastName, $billingAddr1, $billingAddr2 = "", $billingCity, $billingState, $billingZIP, $billingCountry = "US", $ccNumber, $ccExpMonth, $ccExpYear, $ccVerificationValue)
 {
     $billing_info = new Recurly_BillingInfo();
     $billing_info->account_code = $account->account_code;
     $billing_info->first_name = $billingFirstName;
     $billing_info->last_name = $billingLastName;
     $billing_info->address1 = $billingAddr1;
     $billing_info->address2 = $billingAddr2;
     $billing_info->city = $billingCity;
     $billing_info->state = $billingState;
     $billing_info->country = $billingCountry;
     $billing_info->zip = $billingZIP;
     $billing_info->year = intval($ccExpYear);
     $billing_info->month = intval($ccExpMonth);
     if (trim($ccVerificationValue) != "") {
         $billing_info->verification_value = $ccVerificationValue;
     }
     if (substr($ccNumber, 0, 5) != "*****") {
         $billing_info->number = $ccNumber;
     }
     $billing_info->ip_address = $_SERVER['REMOTE_ADDR'];
     $account_info = $billing_info->update();
     $account_info = null;
     $currentSubscription = self::getSubscription($account->account_code);
     $currentPlanCode = "";
     $currentPlanCost = 0;
     $newPlanCost = 0;
     if ($planCode != "" && $planCode != "daily") {
         $newPlan = Recurly_Plan::get($planCode);
         $newPlanCost = $newPlan->unit_amount_in_cents;
     }
     if ($currentSubscription) {
         $currentPlanCode = $currentSubscription->plan_code;
         $currentPlan = Recurly_Plan::get($currentPlanCode);
         $currentPlanCost = $currentSubscription->unit_amount_in_cents;
     }
     if ($planCode == "" || $planCode == "daily") {
         // if the plan is being moved from a monthly plan to daily, then we have to cancel subscription.
         if ($currentSubscription) {
             $currentSubscription->cancel();
         }
     } else {
         // if the plan is being moved from one monthly plan to another, then we have to
         // upgrade or downgrade.
         if ($currentSubscription) {
             $currentSubscription->plan_code = $planCode;
             // get the current plan's amount and compare to the new one
             if ($newPlanCost > $currentPlanCost) {
                 // upgrade
                 $currentSubscription->updateImmediately();
             } elseif ($newPlanCost < $currentPlanCost) {
                 $currentSubscription->updateAtRenewal();
             }
         } else {
             // no current subscription and we want a monthly, so just add a new one
             $subscription = new Recurly_Subscription();
             $subscription->plan_code = $planCode;
             $subscription->currency = "USD";
             $account->billing_info = $billing_info;
             $subscription->account = $account;
             $subscription->create();
         }
     }
     return $account_info;
 }
示例#7
0
<?php

require 'vendor/autoload.php';
// Configure the client with your subdomain and API Key
Recurly_Client::$subdomain = 'RECURLY_SUBDOMAIN';
Recurly_Client::$apiKey = 'RECURLY_API_KEY';
$app = new \Slim\Slim();
// Create a new account, subscription, and billing information
$app->post('/api/subscriptions/new', function () use($app) {
    // We wrap this is a try-catch to handle any errors
    try {
        // Specify the minimum subscription attributes: plan_code, account, and currency
        $subscription = new Recurly_Subscription();
        $subscription->plan_code = 'basic';
        $subscription->currency = 'USD';
        // Create an account with a uniqid and the customer's first and last name
        $subscription->account = new Recurly_Account(uniqid());
        $subscription->account->first_name = $_POST['first-name'];
        $subscription->account->last_name = $_POST['last-name'];
        // Now we create a bare BillingInfo with a token
        $subscription->account->billing_info = new Recurly_BillingInfo();
        $subscription->account->billing_info->token_id = $_POST['recurly-token'];
        // Create the subscription
        $subscription->create();
    } catch (Exception $e) {
        // Assign the error message and use it to handle any customer
        // messages or logging
        $error = $e->getMessage();
    }
    // Now we may wish to redirect to a confirmation
    // or back to the form to fix errors.
  public function testUpdateNotes() {
    $this->client->addResponse('GET', '/subscriptions/012345678901234567890123456789ab', 'subscriptions/show-200.xml');
    $this->client->addResponse('PUT', 'https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/notes', 'subscriptions/show-200-changed-notes.xml');

    $subscription = Recurly_Subscription::get('012345678901234567890123456789ab', $this->client);

    $notes = array("customer_notes" => "New Customer Notes", "terms_and_condititions" => "New Terms", "vat_reverse_charge_notes" => "New VAT Notes");

    $subscription->updateNotes($notes);

    foreach($notes as $key => $value) {
      $this->assertEquals($subscription->$key, $value);
    }
  }
 public function testPreviewChangeSubscription()
 {
     $this->client->addResponse('GET', '/subscriptions/012345678901234567890123456789ab', 'subscriptions/show-200.xml');
     $this->client->addResponse('POST', 'https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/preview', 'subscriptions/preview-200-change.xml');
     $subscription = Recurly_Subscription::get('012345678901234567890123456789ab', $this->client);
     $subscription->plan_code = 'gold';
     $subscription->preview();
     $this->assertEquals('5000', $subscription->cost_in_cents);
     $this->assertEquals('gold', $subscription->plan_code);
 }
示例#10
0
RecurlyClient::SetAuth(RECURLY_API_USERNAME, RECURLY_API_PASSWORD, RECURLY_SUBDOMAIN, RECURLY_ENVIRONMENT);
// Setting timezone for time() function.
date_default_timezone_set('America/New_York');
// Replace with the user's unique ID in your system
$account_id = '14';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    //Recurly Account
    $account = new RecurlyAccount($account_id);
    $account->username = $_POST['account']['username'];
    $account->first_name = $_POST['account']['first_name'];
    $account->last_name = $_POST['account']['last_name'];
    $account->email = $_POST['account']['email'];
    //Wordpress Account
    $newWordpressUser = array('user_login' => $_POST['account']['username'], 'user_pass' => $_POST['account']['password'], 'user_nicename' => $_POST['account']['first_name'] . ' ' . $_POST['account']['last_name'], 'nickname' => $_POST['account']['first_name'] . ' ' . $_POST['account']['last_name'], 'first_name' => $_POST['account']['first_name'], 'last_name' => $_POST['account']['last_name'], 'display_name' => $_POST['account']['first_name'] . ' ' . $_POST['account']['last_name'], 'user_registered' => date("Y-m-d H:i:s"), 'user_email' => $_POST['account']['email']);
    //Recurly Subscription
    $subscription = new Recurly_Subscription();
    $subscription->plan_code = $_POST['plan_type'];
    $subscription->billing_info = new Recurly_BillingInfo();
    $billing_info = $subscription->billing_info;
    $billing_info->first_name = $account->first_name;
    $billing_info->last_name = $account->last_name;
    $billing_info->address1 = $_POST['billing_info']['address1'];
    $billing_info->address2 = $_POST['billing_info']['address2'];
    $billing_info->city = $_POST['billing_info']['city'];
    $billing_info->state = $_POST['billing_info']['state'];
    $billing_info->country = $_POST['billing_info']['country'];
    $billing_info->zip = $_POST['billing_info']['zip'];
    $billing_info->number = $_POST['credit_card']['number'];
    $billing_info->year = intval($_POST['credit_card']['year']);
    $billing_info->month = intval($_POST['credit_card']['month']);
    $billing_info->verification_value = $_POST['credit_card']['verification_value'];
function GetUserRecurlySubscription()
{
    $account = GetUserRecurlyAccount();
    return Recurly_Subscription::get($account->account_code);
}
 public function testGetSubscriptionRedemptions()
 {
     $this->client->addResponse('GET', '/subscriptions/012345678901234567890123456789ab', 'subscriptions/show-200.xml');
     $this->client->addResponse('GET', 'https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/redemptions', 'subscriptions/redemptions-200.xml');
     $subscription = Recurly_Subscription::get('012345678901234567890123456789ab', $this->client);
     $redemptions = $subscription->redemptions->get();
     $this->assertEquals(2, $redemptions->count());
     foreach ($redemptions as $r) {
         $this->assertInstanceOf('Recurly_CouponRedemption', $r);
     }
 }