Paolo Broccardo
Paolo Broccardo

Reputation: 1744

Coldfusion timestamp datatype error

I am implementing an external wrapper for the Stripe API in Coldfusion.

One of the functions I am calling takes an argument of type "timestamp", as seen below:

public struct function updateSubscription(required string customerid, required string planid, string coupon='', boolean prorate=true, timestamp trial_end, any card) 
{
...
}

I am passing a valid date (tested and IsDate() resulted in "YES") to the trial_end argument but it is giving me a "not of type timestamp" error.

What do I need to do to this date to get the function call to work properly?

Thanks

UPDATE: FULL FUNCTION ADDED:

public struct function updateSubscription(required string customerid, required string planid, string coupon='', boolean prorate=true, timestamp trial_end, any card) {

    local.HTTPService = createHTTPService('POST');
    local.HTTPService.addParam(type='formfield',name='plan',value=arguments.planid);

    local.HTTPService.setUrl(getBaseUrl() & 'customers/' & arguments.customerid & '/subscription');
    if (Len(Trim(arguments.coupon))) {
        local.HTTPService.addParam(type='formfield',name='coupon',value=Trim(arguments.coupon));
    }
    local.HTTPService.addParam(type='formfield',name='prorate',value=arguments.prorate);
    if (StructKeyExists(arguments,'trial_end') AND IsDate(arguments.trial_end)) {
        loca.intUTCDate = timeToUTCInt(arguments.trial_end);
        local.HTTPService.addParam(type='formfield',name='trial_end',value=local.intUTCDate);
    }
    if (StructKeyExists(arguments,'card') AND isStruct(arguments.card)) {
        local.HTTPService.addParam(type='formfield',name='card[number]',value=arguments.card.number);
        local.HTTPService.addParam(type='formfield',name='card[exp_month]',value=arguments.card.exp_month);
        local.HTTPService.addParam(type='formfield',name='card[exp_year]',value=arguments.card.exp_year);
        if (StructKeyExists(arguments,'card.cvc')) {
            local.HTTPService.addParam(type='formfield',name='card[cvc]',value=arguments.card.cvc);
        }
        if (StructKeyExists(arguments,'card.name') AND Len(Trim(arguments.card.name))) {
            local.HTTPService.addParam(type='formfield',name='card[name]',value=arguments.card.name);
        }
        if (StructKeyExists(arguments,'card.address_line1') AND Len(Trim(arguments.card.address_line1))) {
            local.HTTPService.addParam(type='formfield',name='card[address_line1]',value=Trim(arguments.card.address_line1));
        }
        if (StructKeyExists(arguments,'card.address_line2') AND Len(Trim(arguments.card.address_line2))) {
            local.HTTPService.addParam(type='formfield',name='card[address_line2]',value=Trim(arguments.card.address_line2));
        }
        if (StructKeyExists(arguments,'card.address_zip') AND Len(Trim(arguments.card.address_zip))) {
            local.HTTPService.addParam(type='formfield',name='card[address_zip]',value=Trim(arguments.card.address_zip));
        }
        if (StructKeyExists(arguments,'card.address_state') AND Len(Trim(arguments.card.address_state))) {
            local.HTTPService.addParam(type='formfield',name='card[address_state]',value=Trim(arguments.card.address_state));
        }
        if (StructKeyExists(arguments,'card.address_country') AND Len(Trim(arguments.card.address_country))) {
            local.HTTPService.addParam(type='formfield',name='card[address_country]',value=Trim(arguments.card.address_country));
        }
    } else if (StructKeyExists(arguments,'card')) {
        local.HTTPService.addParam(type='formfield',name='card',value=Trim(arguments.card));
    }
    local.HTTPResult = local.HTTPService.send().getPrefix();

    if (NOT isDefined("local.HTTPResult.statusCode")) {
        throw(type='Stripe',errorcode="stripe_unresponsive", message="The Stripe server did not respond.", detail="The Stripe server did not respond.");
    } else if (left(local.HTTPResult.statusCode,3) NEQ "200") {
        throw(type='Stripe',errorcode=local.HTTPResult.statusCode, message=local.HTTPResult.statuscode, detail=local.HTTPResult.filecontent);
    }
    return deserializeJSON(local.HTTPResult.filecontent);
}

Upvotes: 1

Views: 460

Answers (1)

Adam Cameron
Adam Cameron

Reputation: 29870

timestamp is not a native CF data type, so CF is trying to find a CFC called timestamp.cfc.

I think you just mean date in this case.

Upvotes: 8

Related Questions