I'm using the Charge API to get a customer's next invoice date in a template:

{exp:charge:api call="Stripe_Invoice::upcoming" param_name="customer" key="{customer_id}"}
{if has_error}
        {if '{next_payment_attempt}' != ''}
            Your plan will renew automatically on:
            {exp:low_nice_date date="{next_payment_attempt}" format="%n/%j/%Y"}.

This calls the api() function in the module, and I can clearly see where {data} is being set:

$data = ee()->charge_stripe->api_call($call_name, $call_val, $call_param_name);

if ($data === false) {
    $ret['has_error'] = true;
    $ret['error_message'] = ee()->charge_stripe->api_error_message;
} else {
    $ret['data'] = $data;
    $ret['has_error'] = false;
    $ret['error_message'] = '';

If I var_dump($data['next_payment_attempt']) there I get a timestamp, as expected. But in the template I get an error about Array to String conversion. I can manually add the line $ret['next_payment_attempt'] = $data['next_payment_attempt']; and then use {next_payment_attempt} in my template.

Why can't I use {data}{next_payment_attempt}{/data} in my template without modifying the PHP directly, when it's clear that $data['next_payment_attempt'] is a timestamp?


Alas I don't know the add-on, but for a tag pair, it needs to be a numerical indexed array for the return variable, so $ret['data'] = $data would need to be $ret['data'] = array($data), so that the variable pair has something to loop through, so the output should be in this structure: $ret['data'][0]['next_payment_attempt'] - even if it only contains 1 set of data (1 loop).

  • Sure enough, I edited the PHP to do $ret['data'] = array($data) and now everything works as expected Feb 23 '16 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.