1

我正在为 Coldfusion 中的 Stripe API 实现一个外部包装器。

我正在调用的函数之一采用“时间戳”类型的参数,如下所示:

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

我将一个有效日期(经过测试并且 IsDate() 导致“是”)传递给 trial_end 参数,但它给了我一个“不是时间戳类型”错误。

到目前为止,我需要做什么才能使函数调用正常工作?

谢谢

更新:添加了全功能:

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);
}
4

1 回答 1

8

timestamp不是原生CF 数据类型,因此 CF 正在尝试查找名为 timestamp.cfc 的 CFC。

我想你的意思是date在这种情况下。

于 2012-09-05T09:47:18.100 回答