Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Subscription and user (with billing info) #293

Closed
joneslloyd opened this issue Jan 10, 2017 · 2 comments
Closed

Create Subscription and user (with billing info) #293

joneslloyd opened this issue Jan 10, 2017 · 2 comments
Labels
V2 V2 Client

Comments

@joneslloyd
Copy link

Hi there,

Thanks for creating this PHP wrapper/client for Recurly -- Very useful for us.

Also, apologies if this isn't the right place to post this, but:

I'm not very clear on how to (via the PHP wrapper) create a Subscription and user account (with billing info) all in one go.

I've read the API documentation (which makes total sense to me), but I can't see how to pass the relevant user info (and billing info) when calling the create function in the Recurly_Subscription class, given that it doesn't accept any parameters.

Any pointers on this would be great.

Thanks in advance!

@joneslloyd
Copy link
Author

I spoke too soon!

<?php

try {
  $subscription = new Recurly_Subscription();
  $subscription->plan_code = 'gold';
  $subscription->currency = 'EUR';

  $account = new Recurly_Account();
  $account->account_code = 'b6f5783';
  $account->email = 'verena@example.com';
  $account->first_name = 'Verena';
  $account->last_name = 'Example';

  $billing_info = new Recurly_BillingInfo();
  $billing_info->number = '4111-1111-1111-1111';
  $billing_info->month = 12;
  $billing_info->year = 2019;
  $billing_info->verification_value = '123';
  $billing_info->address1 = '400 Alabama St';
  $billing_info->city = 'San Francisco';
  $billing_info->state = 'CA';
  $billing_info->country = 'US';
  $billing_info->zip = '94110';

  $account->billing_info = $billing_info;
  $subscription->account = $account;

  $subscription->create();

  print "Subscription: $subscription";
} catch (Recurly_ValidationError $e) {
  print "Invalid Plan, Subscription, Account, or BillingInfo data: $e";
}

@bhelx
Copy link
Contributor

bhelx commented Jan 10, 2017

👍 thanks for posting your solution

@bhelx bhelx added the V2 V2 Client label Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V2 V2 Client
Projects
None yet
Development

No branches or pull requests

2 participants