0

I've a free plan among some other plans. when user signup with Free Plan I create the Account in RECURLY without subscription & Billing Information. When user tries to upgrade to some paid plan. I create a subscription. But with subscription, I also need to set the Billing account token in 1 Request, How i can do that in Recurly using Ruby on rails.

 if account.present && subscription.blank?
  recurly_result =subscription.update_attributes(subscription attributes & Account billing token)
 end

2 Answers2

1

You can use the Recurly.js functionality to do this. When you make the subscription call, just use the existing account_code, so that the subscription and billing information generated during the signup will get associated with the existing account. Take a look at the code samples at https://github.com/recurly/recurly-js-examples

Rachel Quick
  • 1,804
  • 9
  • 8
0

Try this

// Specify the minimum subscription attributes: plan_code, account, and currency
           $subscription = new Recurly_Subscription();
           $identity_token  =    "identity token"
           $subscription    =    Recurly_Subscription::get($identity_token);

          try{
            $accountcode =  "account code"; 
            $account = Recurly_Account::get($accountcode);
            $account->first_name = $_POST['first-name'];
            $account->last_name = $_POST['last-name'];
            $account->email = $_POST['email'];
            $account->update();

           $billing_info = new Recurly_BillingInfo();
           $billing_info->account_code = $accountcode;
           $billing_info->token_id = $_POST['recurly-token'];
           $billing_info->update(); 

           $sub_response          =  $subscription->updateImmediately();
           $uuid                  =  $subscription->uuid;

           .........
           .........
           }catch (Exception $e){
             echo $e->getMessage();

           }

Its PHP code , you can adjust it as per ROR

Ashish Chaturvedi
  • 1,352
  • 3
  • 13
  • 37