CFHTTP based on PHP Example

Contributor ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

I am trying to create reports in Stripe but their examples are PHP. I've had success with all their other functions I'm just stuck on reports. The PHP example is: 

 

POST 
/v1/reporting/report_runs

 

// Note that a live-mode API key is required.
\Stripe\Reporting\ReportRun::create([
  'report_type' => 'balance_change_from_activity.itemized.3',
  'parameters' => [
    'interval_start' => '1577865600',
    'interval_end' => '1580544000',
    'timezone' => 'America/Los_Angeles',
  ],
]);

 

My code looks like:

 

<!--- Data related to call --->
<cfset stripe_api_key = 'sk_live_XXXXXX' />
<cfset stripe_api_url = 'https://api.stripe.com/v1/' />
<cfset report_type = 'payout_reconciliation.summary.1' />
<cfset Interval_Start = #DateDiff("s", DateConvert("utc2Local", "January 1 1970 00:00"), Start)# />	
<cfset Interval_End = #DateDiff("s", DateConvert("utc2Local", "January 1 1970 00:00"), End)# />
<cfset timezone = 'America/New_York' />
<!--- Call --->
<cffunction name="createReport" access="private">
	<cfargument name="interval_start" type="numeric" required="true">
	<cfargument name="interval_end" type="numeric" required="true">
	<cfargument name="timezone" type="string" required="true" default="">
	<cfargument name="report_type" type="string" required="true" default="">
		
	<cfhttp url="#stripe_api_url#reporting/report_runs" method="POST" username="#stripe_api_key#" password="" charset="utf-8" result="report_result">
	   <cfhttpparam type="formfield" name="Report_Type" value="#arguments.report_type#" >
		<cfhttpparam type="formfield" name="parameters[interval_start]" value="#arguments.interval_start#" >
		<cfhttpparam type="formfield" name="parameters[interval_end]" value="#arguments.interval_end#" >
		<cfhttpparam type="formfield" name="parameters[timezone]" value="#arguments.timezone#" >		
	</cfhttp>	
	<cfif NOT isDefined("report_result.statusCode")>
		<cfthrow type='Stripe' errorcode="stripe_unresponsive" message="The Stripe server did not respond." detail="The Stripe server did not respond." />
	<cfelseif left(report_result.statusCode,3) NEQ "200">
		<cfreturn deserializeJSON(report_result.filecontent) />
	</cfif>
	<cfreturn deserializeJSON(report_result.filecontent) />	
</cffunction>

 

The request post body on Stripe:

 

{
  "Report_Type": "payout_reconciliation.summary.1",
  "parameters": {
    "interval_start": "1589256000",
    "interval_end": "1589342400",
    "timezone": "America/New_York"
  }
}

 

 It returns:

 

{
  "error": {
    "code": "parameter_unknown",
    "doc_url": "https://stripe.com/docs/error-codes/parameter-unknown",
    "message": "Received unknown parameter: Report_Type",
    "param": "Report_Type",
    "type": "invalid_request_error"
  }
}

 

I am guessing it's got to do with this part of the PHP which I don't understand:

\Stripe\Reporting\ReportRun::create

 

I appreciate any help..... 

Views

175

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Contributor , May 12, 2020 May 12, 2020
Answered my own question... Report_Type needs to be report_type. After posting this it hit me if it wants the time in epoch time then it's likely Linux and case sensitive. 

Likes

Translate

Translate
Contributor ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

LATEST

Answered my own question... Report_Type needs to be report_type. After posting this it hit me if it wants the time in epoch time then it's likely Linux and case sensitive. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines