Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CFHTTP based on PHP Example

Contributor ,
May 12, 2020 May 12, 2020

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..... 

852
Translate
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. 

Translate
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. 

Translate
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
Contributor ,
Nov 08, 2021 Nov 08, 2021

Hi, I see you have successfully set up a PHP payment server with Coldfusion. I would like to do the same for my application. Do you have any files or a repo that I could use as examples?

Thank you in advance for your help.

Regards,

Translate
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
Contributor ,
Nov 08, 2021 Nov 08, 2021

Look here:  https://github.com/Gary-Hanna/Stripe-Coldfusion-API

 

Let me know if you need any help.

Translate
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
Contributor ,
Nov 09, 2021 Nov 09, 2021

Thank you for your answer. Have you tried using version 3 of the Stripe API which gives more functionality?

Translate
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
Community Expert ,
Nov 27, 2021 Nov 27, 2021

It's good news that it's working, of course. But may I share an idea, based on the information you give above.

 

What about simplifying the HTTP-POST call to:

 

<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="">

	<cfset var params = '{  "interval_start": "#arguments.interval_start#",
						    "interval_end": "arguments.interval_end",
						    "timezone": "#arguments.timezone#"
						  }'>	
						  
	<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#" encoded="false">
		<cfhttpparam type="formfield" name="parameters" value="#params#" encoded="false" >	
	</cfhttp>	
</cffunction>

 

 

Translate
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
Contributor ,
Dec 07, 2021 Dec 07, 2021
LATEST

Merci à tous !

Translate
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
Resources