Skip to main content
Inspiring
May 13, 2022
Answered

Integrating CFML with Stripe API

  • May 13, 2022
  • 2 replies
  • 1356 views

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.

    This topic has been closed for replies.
    Correct answer VincentL12

    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.
     

     


    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

     

    2 replies

    Charlie Arehart
    Braniac
    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)
    Inspiring
    June 7, 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.

     

    BKBK
    Braniac
    June 9, 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?

     

     


    <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#})>
    BKBK
    Braniac
    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.

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