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

Integrating CFML with Stripe API

Explorer ,
May 13, 2022 May 13, 2022

I am trying to pass variable values from CFML forms to the Stripe API (Checkout API), but have not been able to find relevant documentation.  The data can be passed through hidden variables or by Javascript/Ajax. 

 

Does anyone have any useful information on this?

 

Thanks in advance.

1.2K
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

Explorer , Jun 09, 2022 Jun 09, 2022

I have read the guidelines and I think I can post the following:

 

The answer to the above issue can be found here:

 

https://stackoverflow.com/questions/72568176/passing-child-parameters-to-stripe-api-from-cfml/72568336#72568336

 

Translate
Community Expert ,
May 13, 2022 May 13, 2022

I think you're looking at the wrong place. Stripe.com is the place to be.

 

They will tell you how to integrate their API - irrespective of whether you're using PHP, JSP, C# .NET, Python or ColdFusion. I have had a look at the Stripe site and can confirm that they have elaborate documentation. See for example the the Stripe documentation on Checkout.

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 ,
May 13, 2022 May 13, 2022

Another idea: search this forum for the word stripe. You could then get in touch with fellow ColdFusion developers who are using Stripe.

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
Explorer ,
May 13, 2022 May 13, 2022

I have been in contact with the staff at Stripe, and they have never heard of ColdFusion. As such they are unable to 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
Community Expert ,
May 13, 2022 May 13, 2022
 

I have been in contact with the staff at Stripe, and they have never heard of ColdFusion. 


By VincentL12

That confirms my point. The producer of an API need not know anything about the API's users, be they PHP, JSP, C# .NET, Python or ColdFusion.

 

The Stripes API documentation should show you how to do a checkout, irrespective of your programming environment.

 

Make a start. Then bring your ColdFusion code to the forum for discussion.

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 ,
May 13, 2022 May 13, 2022

Vincent, are you really looking only specifically for docs of cf calling stripe? If so, you may not readily find that, or what you find may be dated.

 

But if you may mean that you don't know how to even start, you'd want to use cfhttp, and then also cfhttpparam which can be used to pass in variables (such as to mimick form, url, and cgi fields), headers, and more.

 

So when wanting to call some api, you would use a combination of docs for that api and translation of that cfhttp/cfhttpparam calls. Then you would process that result, which may be a result passed back to the cfhttp call or perhaps headers returned. Those can be seen in either the cfhttp struct or by naming a RESULT attribute in the cfhttp.

 

BTW, besides the cfml reference on the tag (or its cfscript equivalent), there is also discussion in the separate cf developer guide. Then as bkbk noted you can find various other articles folks have written, whether on calling stripe specifically or APIs in general, which may help with far more details.

 

Let us know how you go. 


/Charlie (troubleshooter, carehart. org)
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
Explorer ,
Jun 07, 2022 Jun 07, 2022

Charlie,

 

Thanks for the response and unfortunately I could not look at this during the last month.

 

I am now trying to use CFHTTP to access the Stripe API - I can connect via Ajax with code such as 

 

<script src="https://js.stripe.com/v3/"></script>

<cfhttp method = "POST" url="https://api.stripe.com/v1/customers">

<cfhttpparam type="header" name="Authorization" value="Bearer sk_test_51..................................">

<cfhttpparam type="header" name="name" value =#Customer_Name#>

<cfhttpparam type="header" name="address.line1" value = #Address_1#>

.................................................

</cfhttp>

 

I get errors if I use type = "FormField" or "Body" in place of "header" - I am not sure why. Then on trying to retrieve data I am using code such as 

 

<cfhttp method = "GET" url="https://api.stripe.com/v1/customers/cus_4QE41GDczMg5d5" result = "content_1">

<cfhttpparam type="header" name="Authorization" value="Bearer sk_test............">

</cfhttp>

<CFSET content_1_data = DeserializeJSON(content_1.filecontent)>

<cfoutput>
#content_1_data.name#
</cfoutput>

 

but this gives an error.

 

Thanks in advance for any comments.

 

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 ,
Jun 07, 2022 Jun 07, 2022

Well, it would really help to know the errors, both from the first cfhttp that failed and then from your attempt to use the result of the second.

 

More specifically, you should share the dump of that result of the second. Does it look like what your code is wanting to process? 

 


/Charlie (troubleshooter, carehart. org)
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
Explorer ,
Jun 07, 2022 Jun 07, 2022

Thanks for the reply.

 

My code is processing as I can see records generating on the Stripe dashboard. I have FormField working now.

 

For some reason my retrieval code does not function - I simply get an error message that the element name is undefined. I checked the key, and I am using the correct one (from the dashboard) assigned for testing. I  made sure the customer id's are the same..

 

I have a problem with tokens - the JSON is returning an error. If I cannot sort this out in a few hours, I will post the code giving the error.

 

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
Explorer ,
Jun 07, 2022 Jun 07, 2022

I have checked the JSON in the retrieving code and it shows an error - Invalid API key. If I can fix this the code should work I think.

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
Explorer ,
Jun 07, 2022 Jun 07, 2022

The retrieval code is now working - many thanks. If I cannot sort out the code for the tokens I will post again.

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
Explorer ,
Jun 08, 2022 Jun 08, 2022

I will continue the discussion here.

 

The above code executes correctly, but I have a problem with fields which have a child attribute. So for "address" I have tried

 

<CFSET Address_1 = SerializeJSON('{"line1: #Street_1#", "line2:" #Street_2#. "town: #Town_1#,", "country: #country_code#"}')>
<cfhttpparam type="FormField" name="address" value = '#Address_1#'>

 

but this code produces an error

 

"address": "\"{\\\"line1: ..........\\\"}\"",  etc.

{
 
"error": {
"message": "Invalid object",
"param": "address",
"type": "invalid_request_error"
}
 
}
 

Anyone have any ideas or comments on this?

 

 

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
Explorer ,
Jun 08, 2022 Jun 08, 2022

I cannot edit the above, but I have got the , in the correct places -not as shown (and not with .)

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 ,
Jun 09, 2022 Jun 09, 2022

<CFSET Address_1 = SerializeJSON('{"line1: #Street_1#", "line2:" #Street_2#. "town: #Town_1#,", "country: #country_code#"}')>
<cfhttpparam type="FormField" name="address" value = '#Address_1#'>

 

but this code produces an error

 

Anyone have any ideas or comments on this?


By VincentL12

 

What you are serializing here is just a string. So the result will just be a string, which can be considered as JSON.

 

I suspect you actually wish to serialize a struct. If so, then you will need something like

<CFSET Address_1 = SerializeJSON({line1: #Street_1#, line2: #Street_2#, town: #Town_1#, country: #country_code#})>
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
Explorer ,
Jun 09, 2022 Jun 09, 2022

Thanks for this response, but the code (and small ,modifications of it) produces an error from Stripe:

....

"address": "{\"CITY\":\"Jacobstown\"}",

..........

 

"error": {
"message": "Invalid object",
"param": "address",
"type": "invalid_request_error"
}
This apparently means that a parameter is invalid.  It should be "city" and not "town" (see earlier code) but something is wrong.
 

 

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
Explorer ,
Jun 09, 2022 Jun 09, 2022
LATEST

I have read the guidelines and I think I can post the following:

 

The answer to the above issue can be found here:

 

https://stackoverflow.com/questions/72568176/passing-child-parameters-to-stripe-api-from-cfml/725683...

 

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