Web Connection
Posting MetaData to Stripe
Gravatar is a globally recognized avatar based on your email address. Posting MetaData to Stripe
  Carl Chambers
  All
  Jul 9, 2015 @ 11:08am
I can't figure out how to structure the Post Key when trying to pass meta data in a call to Stripe.

Their info on the subject is here with code samples in various languages that I don't really know.

Below is a sample of the code I use to pass simple values.

************************************************************************
* Stripe :: CreateCoupon
***************************
*** Function: Creates a coupon.
*** Return: Coupon object, .NULL. on failure
************************************************************************

FUNCTION CreateCoupon
*---------------------
LPARAMETERS tcID, tnPercentOff, tcDuration, tnDurationInMonths, ;
tnAmountOff, tcCurrency, ;
tnMaxRedemptions, tuRedeemBy, tcMetaData

IF EMPTY(m.tcID) OR ;
(EMPTY(m.tnPercentOff) AND ;
EMPTY(m.tnAmountOff) AND ;
EMPTY(m.tcCurrency))
RETURN NULL
ENDIF

LOCAL loHTTP, lcURL, lcJSON, loCoupon, llSuccess
DO wwHttp
loHTTP = CREATEOBJECT([WWC_WWHTTP])
loHTTP.AddHeader("Authorization","Bearer " + THIS.cSecretKey)

*
* Adding plain values...
*

loHTTP.AddPostKey("id",m.tcID)
loHTTP.AddPostKey("duration",m.tcDuration)
IF m.tcDuration = "repeating"
loHTTP.AddPostKey("duration_in_months",m.tnDurationInMonths)
ENDIF
*- etc....

*- SNIPPED FOR BREVITY -*

*
* >>>>>>>>> How to structure the meta data? <<<<<<<<<<
*
* It's supposed to be in key-value pairs
*
*tcMetaDta = "referrer_credit: 500" && NOPE
*tcMetaDta = ["referrer_credit": "500"] && NOPE
*tcMetaDta = [{"referrer_credit": "500"}] && NOPE

*
* Add the Meta Data (doesn't work though)
*
IF VARTYPE(m.tcMetaData) = "C" AND NOT EMPTY(m.tcMetaData)
loHTTP.AddPostKey("metadata",m.tcMetaData)
ENDIF

lcURL = "https://api.stripe.com/v1/coupons"
lcJSON = loHttp.HTTPGet(m.lcURL)

loCoupon = .NULL.
llSuccess = THIS.ParseResponse(m.lcJSON,@loCoupon)
IF m.llSuccess
RETURN m.loCoupon
ELSE
RETURN .NULL.
ENDIF

ENDFUNC
* EOF Stripe::CreateCoupon

Here's the Stripe response.

{
"error": {
"type": "invalid_request_error",
"message": "Invalid metadata: metadata must be a set of key-value pairs",
"param": "metadata"
}
}

Any ideas on how to do this?

Thanks,
Carl

Gravatar is a globally recognized avatar based on your email address. Re: Posting MetaData to Stripe
  Rick Strahl
  Carl Chambers
  Jul 9, 2015 @ 12:28pm
Looks like your meta data key and value are not formatted correctly. Looks like you need something like:

loHttp.AddPostKey("metadata[order_id]","6735")

+++ Rick ---



I can't figure out how to structure the Post Key when trying to pass meta data in a call to Stripe.

Their info on the subject is here with code samples in various languages that I don't really know.

Below is a sample of the code I use to pass simple values.

************************************************************************
* Stripe :: CreateCoupon
***************************
*** Function: Creates a coupon.
*** Return: Coupon object, .NULL. on failure
************************************************************************

FUNCTION CreateCoupon
*---------------------
LPARAMETERS tcID, tnPercentOff, tcDuration, tnDurationInMonths, ;
tnAmountOff, tcCurrency, ;
tnMaxRedemptions, tuRedeemBy, tcMetaData

IF EMPTY(m.tcID) OR ;
(EMPTY(m.tnPercentOff) AND ;
EMPTY(m.tnAmountOff) AND ;
EMPTY(m.tcCurrency))
RETURN NULL
ENDIF

LOCAL loHTTP, lcURL, lcJSON, loCoupon, llSuccess
DO wwHttp
loHTTP = CREATEOBJECT([WWC_WWHTTP])
loHTTP.AddHeader("Authorization","Bearer " + THIS.cSecretKey)

*
* Adding plain values...
*

loHTTP.AddPostKey("id",m.tcID)
loHTTP.AddPostKey("duration",m.tcDuration)
IF m.tcDuration = "repeating"
loHTTP.AddPostKey("duration_in_months",m.tnDurationInMonths)
ENDIF
*- etc....

*- SNIPPED FOR BREVITY -*

*
* >>>>> How to structure the meta data? <<<<<
*
* It's supposed to be in key-value pairs
*
*tcMetaDta = "referrer_credit: 500" && NOPE
*tcMetaDta = ["referrer_credit": "500"] && NOPE
*tcMetaDta = [{"referrer_credit": "500"}] && NOPE

*
* Add the Meta Data (doesn't work though)
*
IF VARTYPE(m.tcMetaData) = "C" AND NOT EMPTY(m.tcMetaData)
loHTTP.AddPostKey("metadata",m.tcMetaData)
ENDIF

lcURL = "https://api.stripe.com/v1/coupons"
lcJSON = loHttp.HTTPGet(m.lcURL)

loCoupon = .NULL.
llSuccess = THIS.ParseResponse(m.lcJSON,@loCoupon)
IF m.llSuccess
RETURN m.loCoupon
ELSE
RETURN .NULL.
ENDIF

ENDFUNC
* EOF Stripe::CreateCoupon

Here's the Stripe response.

{
"error": {
"type": "invalid_request_error",
"message": "Invalid metadata: metadata must be a set of key-value pairs",
"param": "metadata"
}
}

Any ideas on how to do this?

Thanks,
Carl


Gravatar is a globally recognized avatar based on your email address. Re: Posting MetaData to Stripe
  Carl Chambers
  Rick Strahl
  Jul 9, 2015 @ 03:48pm
That did it!
Thanks, Rick.


Looks like your meta data key and value are not formatted correctly. Looks like you need something like:

loHttp.AddPostKey("metadata[order_id]","6735")

+++ Rick ---



I can't figure out how to structure the Post Key when trying to pass meta data in a call to Stripe.

Their info on the subject is here with code samples in various languages that I don't really know.

Below is a sample of the code I use to pass simple values.

************************************************************************
* Stripe :: CreateCoupon
***************************
*** Function: Creates a coupon.
*** Return: Coupon object, .NULL. on failure
************************************************************************

FUNCTION CreateCoupon
*---------------------
LPARAMETERS tcID, tnPercentOff, tcDuration, tnDurationInMonths, ;
tnAmountOff, tcCurrency, ;
tnMaxRedemptions, tuRedeemBy, tcMetaData

IF EMPTY(m.tcID) OR ;
(EMPTY(m.tnPercentOff) AND ;
EMPTY(m.tnAmountOff) AND ;
EMPTY(m.tcCurrency))
RETURN NULL
ENDIF

LOCAL loHTTP, lcURL, lcJSON, loCoupon, llSuccess
DO wwHttp
loHTTP = CREATEOBJECT([WWC_WWHTTP])
loHTTP.AddHeader("Authorization","Bearer " + THIS.cSecretKey)

*
* Adding plain values...
*

loHTTP.AddPostKey("id",m.tcID)
loHTTP.AddPostKey("duration",m.tcDuration)
IF m.tcDuration = "repeating"
loHTTP.AddPostKey("duration_in_months",m.tnDurationInMonths)
ENDIF
*- etc....

*- SNIPPED FOR BREVITY -*

*
* >>>>> How to structure the meta data? <<<<<
*
* It's supposed to be in key-value pairs
*
*tcMetaDta = "referrer_credit: 500" && NOPE
*tcMetaDta = ["referrer_credit": "500"] && NOPE
*tcMetaDta = [{"referrer_credit": "500"}] && NOPE

*
* Add the Meta Data (doesn't work though)
*
IF VARTYPE(m.tcMetaData) = "C" AND NOT EMPTY(m.tcMetaData)
loHTTP.AddPostKey("metadata",m.tcMetaData)
ENDIF

lcURL = "https://api.stripe.com/v1/coupons"
lcJSON = loHttp.HTTPGet(m.lcURL)

loCoupon = .NULL.
llSuccess = THIS.ParseResponse(m.lcJSON,@loCoupon)
IF m.llSuccess
RETURN m.loCoupon
ELSE
RETURN .NULL.
ENDIF

ENDFUNC
* EOF Stripe::CreateCoupon

Here's the Stripe response.

{
"error": {
"type": "invalid_request_error",
"message": "Invalid metadata: metadata must be a set of key-value pairs",
"param": "metadata"
}
}

Any ideas on how to do this?

Thanks,
Carl



Gravatar is a globally recognized avatar based on your email address. Re: Posting MetaData to Stripe
  Todd Landrum
  Carl Chambers
  Apr 13, 2017 @ 12:13pm

Hi, Carl. Did you make any progress with this? I'm trying to update the StripeX library on VFPX due to Stripe's security change, but hitting a few stumbling blocks.

Gravatar is a globally recognized avatar based on your email address. Re: Posting MetaData to Stripe
  Carl Chambers
  Todd Landrum
  Apr 13, 2017 @ 12:41pm

Hi Todd,

What security change are you referring to?
The last time my app posted meta data to Stripe was 12 days ago and it was fine.

What stumbling blocks are you running into?

Carl

Gravatar is a globally recognized avatar based on your email address. Re: Posting MetaData to Stripe
  Todd Landrum
  Carl Chambers
  Apr 17, 2017 @ 02:34pm

Stripe changed their required SSL level a while back. I was using a CURL library that didn't support it and had to switch to wwHTTP. Got it working now though. Once I get things cleaned up (and the license for wwHTTP figured out), I'll post it to VFPX.

Thanks for getting back to me.

Gravatar is a globally recognized avatar based on your email address. Re: Posting MetaData to Stripe
  Carl Chambers
  Todd Landrum
  Apr 17, 2017 @ 02:50pm

I used wwHttp from the start so I never encountered that.
Glad to hear you got it working.

© 1996-2024