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

Problems using cfhttp to attach a PaymentMethod to a Customer with the Stripe API

Explorer ,
Jun 21, 2022 Jun 21, 2022

Copy link to clipboard

Copied

Following the Stripe documentation, which uses curl, I have tried the code:

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

 

where pm_1LCuutGKxC2502V8WNrkE3Ja is the Payment Method id from the JSON response when the card payment method was set up.

The above code gives the error: You cannot attach a PaymentMethod to a Customer during PaymentMethod creation. Please instead create the PaymentMethod and then attach it using the attachment method of the PaymentMethods API.

Of course the PaymentMethod had already been created, and indeed if I change the ID slightly I get the message No such PaymentMethod: pm_1LCuutGKxC2502V8WNrkE3Ja22 as would be expected.

 

Thanks in advance for any comments.

Views

154

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

You're almost there. You forgot the 'attach' command.

<cfhttp   method = "POST"  url="https://api.stripe.com/v1/payment_methods/pm_1LCuutGKxC2502V8WNrkE3Ja/attach"   result = "result">
    <cfhttpparam type="header" name="Authorization" value="Bearer sk_test_51...."> 
    <cfhttpparam type="FormField" name="customer" value = "cust_admin_1">
.....
</cfhttp>

Votes

Translate

Translate
Community Expert ,
Jun 21, 2022 Jun 21, 2022

Copy link to clipboard

Copied

You're almost there. You forgot the 'attach' command.

<cfhttp   method = "POST"  url="https://api.stripe.com/v1/payment_methods/pm_1LCuutGKxC2502V8WNrkE3Ja/attach"   result = "result">
    <cfhttpparam type="header" name="Authorization" value="Bearer sk_test_51...."> 
    <cfhttpparam type="FormField" name="customer" value = "cust_admin_1">
.....
</cfhttp>

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

Copy link to clipboard

Copied

LATEST

Many thanks. This code works.

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