I'm trying to use the Recurly php client library to integrate the service into a PHP platform and I'm running into an error that doesn't seem to make sense.
I've created a form as described here which gets a token that submits it to my code below to create the actual account and subscription. In my controller, I have the below code:
protected function _actionAdd($context)
{
$viewer = get_viewer();
$plan = $this->getService('repos:subscriptions.plan')->fetch($context->data->get('plan'));
try {
$recurlySubscription = new Recurly_Subscription();
$recurlySubscription->plan_code = $plan->code; // "test-plan"
$recurlySubscription->account = new Recurly_Account();
$recurlySubscription->account->account_code = $viewer->id;
$recurlySubscription->account->first_name = $context->data->get('first_name');
$recurlySubscription->account->last_name = $context->data->get('last_name');
$recurlySubscription->account->email = $viewer->email;
$recurlySubscription->account->billing_info = new Recurly_BillingInfo();
$recurlySubscription->account->billing_info->token_id = $context->data->get('recurly-token');
$recurlySubscription->create();
} catch( Recurly_ValidationError $e) {
print "Invalid Account: $e";
}
}
Most of the above code is from the provided example here. The form includes the plan id in the plan
property which I then look up the plan code from my own database along with the current user's information.
For some reason, I'm getting the following error:
Invalid Account: exception 'Recurly_ValidationError' with message 'Currency is not included in the list, currency not accepted by site, unit amount in cents is not a number.'
I've looked over test-plan
and my site settings numerous times. Both are set to USD as the default currency and I have no idea why unit amount in cents
would matter since I'm not even dealing with it. Any help would be appreciated. Thanks.
For some reason, you're expected to include the currency of the subscription even though it's not specified in the example. Including the below fixes the issue.
$recurlySubscription->currency = 'USD';