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
ENDIFLOCAL 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)
ENDIFlcURL = "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.
ENDIFENDFUNC
* 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
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
ENDIFLOCAL 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)
ENDIFlcURL = "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.
ENDIFENDFUNC
* 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
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
ENDIFLOCAL 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)
ENDIFlcURL = "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.
ENDIFENDFUNC
* 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
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.
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
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.