Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nishapanFFF/0b9b6b7286ccf81e6fc05fe6005fb826 to your computer and use it in GitHub Desktop.
Save nishapanFFF/0b9b6b7286ccf81e6fc05fe6005fb826 to your computer and use it in GitHub Desktop.
// create address
$address = array();
$address['address1'] = '123 main st';
$address['address2'] = '';
$address['city'] = 'Los Angeles';
$address['state'] = 'CO';
$address['zip'] = '91202';
$address['country'] = 'US';
$address['phone'] = '(310)-123-1222';
// create purchase
$purchase = new Recurly_Purchase();
$purchase->currency = 'USD';
$purchase->collection_method = 'automatic';
//create subscription and tie to purchase
$subscription = new Recurly_Subscription();
$subscription->plan_code = 'ffftrial';
$subscription->quantity = 1;
$purchase->subscriptions = array($subscription);
// create purchase ->account
// and tie address info to account
$purchase->account = new Recurly_Account();
$purchase->account->billing_info = array('token_id' => $this->input->post('recurly_token_id'));
$purchase->account->account_code = $this->input->post('email');
$purchase->account->email = $this->input->post('email');
$purchase->account->first_name = $this->input->post('ship_first_name');
$purchase->account->last_name = $this->input->post('ship_last_name');
$purchase->account->address = $address;
// create ajdustment charge for shipping
$charge = new Recurly_Adjustment();
$charge->quantity = 1;
$charge->accounting_code = '<ommitted - private function to get trial accounting code>';
$charge->tax_exempt = false;
$charge->description = 'Fabfitfun Starter Box - Basic Shipping';
$charge->unit_amount_in_cents = 500;
$purchase->adjustments = array($charge);
// submit purchase
$collection = Recurly_Purchase::invoice($purchase); // I'd expect this to fail if address's state/zip does not line up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment