I’m trying to write a module to communicate with Stripe’s payment API. Already, i’ve come across trouble. I keep getting a response: "“Your client sent an invalid HTTP request.” I’ve tried every possible thing I could think of…even b64 encryption…however, nothing seems to work. Any ideas?
Here is my code:
description = "test" email = "test@email.com" api\_key = "pk\_test\_4PRPYs3eM4HQx0ZMBOubGjoy"-- Don't worry, this is a public test key ;) cardNumber = "4242 4242 4242 4242" fullName = "Test Name" expMonth = "07" expYear = "2016" cvc = "432" ------------------------------------------------------------ firstCard = {["number"] = cardNumber, ["exp\_month"] = expMonth, ["exp\_year"] = expYear, ["cvc"] = cvc, ["name"] = fullName} StripeNewRegister = function () local json = require "json" print ("test") newCustomer = {["email"] = email, ["description"] = description} --["card"] = firstCard} print(newCustomer) local function networkListener( event ) if ( event.isError ) then print( "Network error!" ) else print( "RESPONSE: "..event.response ) local data1 = event.response local resp1 = json.decode(data1) print(resp1) local error = resp1.error if error ~= nil then for i = 1, #resp1.error do print(resp1.error[i].type) print(resp1.error[i].message) end end if error == nil then -- Print Functions end end end local key = {["Bearer"] = api\_key} local headers = { ["Authorization Bearer"] = api\_key } local params = {} params.headers = headers params.body = json.encode( newCustomer ) print( "params.body: "..params.body ) network.request( "https://api.stripe.com/v1/customers", "POST", networkListener, params) end StripeNewRegister()