Skip to content

Instantly share code, notes, and snippets.

@tarex
Created March 9, 2015 12:47
Show Gist options
  • Save tarex/8b1193c4d1861e415edb to your computer and use it in GitHub Desktop.
Save tarex/8b1193c4d1861e415edb to your computer and use it in GitHub Desktop.
problem
$subscription = new Recurly_Subscription();
$subscription->plan_code = $_POST['plan_id'];
$subscription->currency = 'USD';
$unique_id = uniqid();
$subscription->account = new Recurly_Account($unique_id);
$subscription->account->first_name = $_POST['user']['first_name'];
$subscription->account->last_name = $_POST['user']['last_name'];
$subscription->account->email = $_POST['user']['email'];
// Now we create a bare BillingInfo with a token
$subscription->account->billing_info = new Recurly_BillingInfo();
$subscription->account->billing_info->token_id = $_POST['token'];
// addons
if( isset( $_POST['selected'] ) ){
$addons = $_POST['selected'] ;
foreach ($addons as $addon) {
$addon1 = new Recurly_SubscriptionAddOn();
$addon1->add_on_code = $addon['name'];
$addon1->quantity = $addon['quantity'];
$addon1->unit_amount_in_cents = $addon['amount'];
$subscription->subscription_add_ons[] = $addon1;
}
}
// Create the subscription
$subscription->create();
if( $_POST['user']['coupon']){
$coupon = Recurly_Coupon::get($_POST['user']['coupon']);
$redemption = $coupon->redeemCoupon($unique_id , 'USD');
}
@ianatrecurly
Copy link

Add at Line 4: $subscription->coupon_code = 'yourCouponCode';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment