Copy link to clipboard
Copied
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 Correct answer
I have read the guidelines and I think I can post the following:
The answer to the above issue can be found here:
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Another idea: search this forum for the word stripe. You could then get in touch with fellow ColdFusion developers who are using Stripe.
Copy link to clipboard
Copied
I have been in contact with the staff at Stripe, and they have never heard of ColdFusion. As such they are unable to help.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
The retrieval code is now working - many thanks. If I cannot sort out the code for the tokens I will post again.
Copy link to clipboard
Copied
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.
Anyone have any ideas or comments on this?
Copy link to clipboard
Copied
I cannot edit the above, but I have got the , in the correct places -not as shown (and not with .)
Copy link to clipboard
Copied
<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#})>
Copy link to clipboard
Copied
Thanks for this response, but the code (and small ,modifications of it) produces an error from Stripe:
....
"address": "{\"CITY\":\"Jacobstown\"}",
..........
Copy link to clipboard
Copied
I have read the guidelines and I think I can post the following:
The answer to the above issue can be found here:

