create() public method

public create ( )
 /**
  * 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);
 }
 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;
 }
示例#3
0
文件: aaa.php 项目: ram-1501/rs
         $recAccount->last_name = $_POST['credit_last_name'];
         $billing_info = new Recurly_BillingInfo();
         $billing_info->address1 = $_POST['street_address'];
         $billing_info->country = $_POST['country'];
         $billing_info->zip = $_POST['zip'];
         $billing_info->city = $_POST['city'];
         if ($_POST['state'] != null && strlen($_POST['state']) > 0) {
             $billing_info->state = $_POST['state'];
         }
         $billing_info->number = $_POST['credit_num'];
         $billing_info->verification_value = $_POST['credit_code'];
         $billing_info->month = $_POST['credit_month'];
         $billing_info->year = $_POST['credit_year'];
         $recAccount->billing_info = $billing_info;
         $subscription->account = $recAccount;
         $rec_response = $subscription->create();
         $xmlResp = new SimpleXMLElement(trim($rec_response->GetBody()));
         $paymentId = $xmlResp->uuid;
         $accountCode = $email;
         $paymentState = $xmlResp->state;
         $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;
     }
 }
示例#4
0
$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.
    if (isset($error)) {
        $app->redirect("ERROR_URL?error={$error}");
    } else {
        $app->redirect("SUCCESS_URL");
    }
});
// Create a new account and billing information
$app->post('/api/accounts/new', function () use($app) {
 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;
 }
    $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'];
    $billing_info->ip_address = $_SERVER['REMOTE_ADDR'];
    $account->billing_info = $billing_info;
    $subscription->account = $account;
    try {
        //Create Recurly Subscription
        $account_info = $subscription->create();
        //Create Wordpress Subscription
        wp_insert_user($newWordpressUser);
        $success_message = 'Your subscription was created successfully.';
    } catch (Recurly_ValidationError $e) {
        $error_message = $e->getMessage();
    } catch (Recurly_Error $e) {
        $error_message = "An error occurred while communicating with our payment gateway. Please try again or " + "contact support.";
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  <title>Grind - Register Member</title>