public function create($username, $first_name, $last_name, $email) { $account = new Recurly_Account($this->account->id); $account->username = $username; $account->first_name = $first_name; $account->last_name = $last_name; $account->email = $email; try { Recurly_Account::get($this->account->id); error_log("*****Account already exists"); $this->recurlyAccount = $account; $result = true; } catch (Recurly_NotFoundError $e) { $account->create(); $result = isset($account->created_at); } if (!$result) { error_log("*****Account not created"); return false; } else { error_log("*****Account successfully created"); $this->recurlyAccount = $account; return true; } }
/** * 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 createRecurlyAccount($id, $fname, $lname, $email) { $account = new Recurly_Account($id); $account->username = $email; $account->first_name = $fname; $account->last_name = $lname; $account->email = $email; $account->create(); return $account; }
} // 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) { try { $account = new Recurly_Account(uniqid()); $account->billing_info = new Recurly_BillingInfo(); $account->billing_info->token_id = $app->request->params('recurly-token'); $account->create(); } catch (Exception $e) { $error = $e->getMessage(); } if ($error) { $app->redirect("ERROR_URL?error={$error}"); } else { $app->redirect("SUCCESS_URL"); } }); $app->put('/api/accounts/:account_code', function ($account_code) use($app) { try { $account = Recurly_Account::get($account_code); $account->first_name = $app->request->params('first-name'); $account->last_name = $app->request->params('last-name'); $account->billing_info = new Recurly_BillingInfo();
public function testCreateWithBillingInfoToken() { $this->client->addResponse('POST', '/accounts', 'accounts/create-201.xml'); $account = new Recurly_Account(null, $this->client); $account->account_code = 'abcdef1234567890'; $account->billing_info = new Recurly_BillingInfo(); $account->billing_info->token_id = 'abc123'; $account->create(); $this->assertInstanceOf('Recurly_Account', $account); }