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

Problems in passing id values to Stripe API objects using cfhttp

Explorer ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

I am able to pass field values to Stripe's Customer object using the code

 

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

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

<cfhttpparam type="FormField" name="id" value = "cust_admin_18">

<cfhttpparam type="FormField" name="address[country]" value = "US"> ........ </cfhttp>

 

However when I try similar code with other Stripe objects, for example Payment_Method, I get an error with the id field. So

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

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

<cfhttpparam type="FormField" name="id" value = "pm_123">

<cfhttpparam type="FormField" name="type" value = "card">

<cfhttpparam type="FormField" name="card[number]" value = "4242424242424242"> 

</cfhttp>

produces an error parameter_unknown - id

 

Changing "FormField" to "header" stops the error, but then the id value is not passed.

 

Thanks in advance for comments.

 

TOPICS
Advanced techniques

Views

175

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

Community Expert , Jun 19, 2022 Jun 19, 2022

In REST APIs a POST request is the usual way to create a resource. After the server creates the resource, it sends the ID of the created resource to the client.

 

Your code suggests that you wish to create a payment method. If so, then the ID is as yet unknown at this point. The server first has to create the payment method, assign it an ID, then return the ID to you.  

 

So your code should be something like

 

<!--- See documentation https://stripe.com/docs/api/payment_methods/create --->
<cfht
...

Votes

Translate

Translate
Community Expert ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

[Moderator moved from Using the Community (forums) to ColdFusion.]

Nancy O'Shea— Product User, Community Expert & Moderator
Alt-Web Design & Publishing ~ Web : Print : Graphics : Media

Votes

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
Community Expert ,
Jun 18, 2022 Jun 18, 2022

Copy link to clipboard

Copied

Help us out: which specific kind of call to that object are you making, that accepts an ID. Not all do, according to the options for that object shown at https://stripe.com/docs/api/payment_methods


/Charlie (troubleshooter, carehart.org)

Votes

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
Community Expert ,
Jun 19, 2022 Jun 19, 2022

Copy link to clipboard

Copied

In REST APIs a POST request is the usual way to create a resource. After the server creates the resource, it sends the ID of the created resource to the client.

 

Your code suggests that you wish to create a payment method. If so, then the ID is as yet unknown at this point. The server first has to create the payment method, assign it an ID, then return the ID to you.  

 

So your code should be something like

 

<!--- See documentation https://stripe.com/docs/api/payment_methods/create --->
<cfhttp method = "POST" url="https://api.stripe.com/v1/payment_methods">
    <cfhttpparam type="header" name="Authorization" value="Bearer sk_test_.....">
    <cfhttpparam type="FormField" name="type" value = "card">
    <cfhttpparam type="FormField" name="card[number]" value = "4242424242424242"> 
    <cfhttpparam type="FormField" name="card[exp_month]" value = "6">
    <cfhttpparam type="FormField" name="card[exp_year]" value = "2023"> 
    <cfhttpparam type="FormField" name="card[cvc]" value = "314"> 
</cfhttp>

 

The API's response should then contain the payment method's ID. It will be something like pm_1LC1qa2eZvKYlo2Cl9jsP6CS

Votes

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

Copy link to clipboard

Copied

Many thanks. This code does some of what I need. I may come back with more comments.

Votes

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
Community Expert ,
Jun 20, 2022 Jun 20, 2022

Copy link to clipboard

Copied

The Stripe API test code

<cfhttp method = "POST" url="https://api.stripe.com/v1/payment_methods">
	<cfhttpparam type="header" name="Authorization" value="Bearer sk_test_4eC39HqLyjWDarjtT1zdp7dc">
	<cfhttpparam type="FormField" name="type" value = "card">
	<cfhttpparam type="FormField" name="card[number]" value = "4242424242424242"> 
	<cfhttpparam type="FormField" name="card[exp_month]" value = "6">
	<cfhttpparam type="FormField" name="card[exp_year]" value = "2023"> 
	<cfhttpparam type="FormField" name="card[cvc]" value = "314"> 
</cfhttp>
<cfdump var="#cfhttp.filecontent#" >

 

gives the result:

{
	"id": "pm_1LCfsY2eZvKYlo2CIsSsRyzb",
	"object": "payment_method",
	"billing_details": {
		"address": {
			"city": null,
			"country": null,
			"line1": null,
			"line2": null,
			"postal_code": null,
			"state": null
		},
		"email": null,
		"name": null,
		"phone": null
	},
	"card": {
		"brand": "visa",
		"checks": {
			"address_line1_check": null,
			"address_postal_code_check": null,
			"cvc_check": "unchecked"
		},
		"country": "US",
		"exp_month": 6,
		"exp_year": 2023,
		"fingerprint": "Xt5EWLLDS7FJjR1c",
		"funding": "credit",
		"generated_from": null,
		"last4": "4242",
		"networks": {
			"available": ["visa"],
			"preferred": null
		},
		"three_d_secure_usage": {
			"supported": true
		},
		"wallet": null
	},
	"created": 1655713358,
	"customer": null,
	"livemode": false,
	"metadata": {},
	"type": "card"
}

Votes

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

Copy link to clipboard

Copied

Many thanks, and I got something like this after reading your previous comment.

 

But now I have difficulty in attaching a Payment Method to a Customer. Stripe give documentation for this, but of course it is in curl.

 

Code such as 

 

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

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

<cfhttpparam type="FormField" name="customer" value = "cust_admin_1">

 

.......

 

</cfhttp>

 

does not work (the Payment Method id used above was generated when the Payment Method record was added).

 

I am trying to make progress through trial and error, but if anyone has a definitive answer, your comments will be much appreciated.

Votes

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
Community Expert ,
Jun 21, 2022 Jun 21, 2022

Copy link to clipboard

Copied

LATEST

I understand. Attac
hing a payment-method to a customer is a separate issue. So I would suggest that you create a new thread for it. If you want you can include in it a link to this thread. Separate threads would make things clearer for each issue.

Votes

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