Using the Recurly API, the following text is returned. What I'm trying to figure out is the easiest way with PHP to extract values from this string and place them into PHP variables.
I've looked at various methods within the PHP manual to find text but being new to PHP the exact process to actually get the values after I've found their location still not apparent to me.
For example, how would I pull the value for plan_code
and remove the quotes around the value so that the result is $plan = 'starter'
?
Recurly_Subscription[href=https://api.recurly.com/v2/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxx] account=<Recurly_Stub[account] href=https://api.recurly.com/v2/accounts/1>, activated_at="2012-07-14 12:55:47 +00:00", currency="USD", current_period_ends_at="2012-08-14 12:55:47 +00:00", current_period_started_at="2012-07-14 12:55:47 +00:00", plan="Recurly_Plan[href=https://api.recurly.com/v2/plans/starter] name="Starter", plan_code="starter", setup_fee_in_cents="<Recurly_CurrencyList []>", unit_amount_in_cents="<Recurly_CurrencyList []>">", quantity=2, state="active", subscription_add_ons=[], unit_amount_in_cents=1200, uuid="1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx3"
You can use Recurly's PHP API:
$result = Recurly_js::fetch($_POST['recurly_token']);
$plan = $result->plan_code;
The token is a subscription object. You can then retrieve additional information about the account and its billing information like this:
$account = $result->account->get();
$billing = $account->billing_info->get();
Retrieve fields from the account (e.g. account holder first name) and its billing info (e.g. last 4 digits of credit card number of record) the same way plan_code is fetched above.
Doing the above is much easier than finding how to do so in Recurly's documentation!