Esempio n. 1
0
File: aaa.php Progetto: ram-1501/rs
<?php

// echo phpversion();
// echo "<br>";
// header('Content-Type: text/plain');
// require_once('settings.inc');
require_once 'modules/api_handler.inc';
require_once 'modules/GoogleAPI.php';
require_once 'twitteroauth/twitteroauth.php';
require_once 'twitteroauth/config.php';
require_once dirname(__DIR__) . '/vendor/recurly_lib/recurly.php';
require_once 'modules/simple_html_dom.php';
Recurly_Client::$subdomain = RECURLY_SUB_DOMAIN;
Recurly_Client::$apiKey = RECURLY_API_KEY;
$api = new ApiHandler();
// Try to setup our session
// Utilities::eClincherSetupUserSession();
// For analytics/backtracing
$bt = debug_backtrace();
$log_response_to_ec_error_handler = false;
array_shift($bt);
$ajax_time_started = microtime(TRUE);
$ajax_label = 'Unknown';
if ($log_response_to_ec_error_handler) {
    ob_start();
}
// Detect and respond to our users that we're in maintenance mode > 1
if (ECConfig::get('MAINTENANCE_MODE') > 1) {
    // echo "Reload page";
    echo file_get_contents(ROOT_PATH . '/web/maintenance.html');
    exit;
 /**
  * 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);
 }
Esempio n. 3
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.