0

I am okay in Classic ASP coding and in the process of learning C#. On stripe, this documentation is available for .net

I would initially like to create a subscription via classic asp, but get errors in the way I refer/syntax errors!

' returning from https://api.stripe.com/v1/customers

   if (oXMLHttp.status = 200) Then
     Set oJSON = New aspJSON
     oJSON.loadJSON(oXMLHttp.responseText)
     stripecustomerid = oJSON.data("id")
     Set oXMLHttp = Nothing
     url = "https://api.stripe.com/v1/subscriptions"
     sendstr = "customer=" & stripecustomerid & **"&items[price].[id]=" & "price_1JZtqEASSxQ8uiR9U5uEZNH9"
     Set oXMLHttp=Server.Createobject("MSXML2.ServerXMLHTTP.6.0")
     oXMLHttp.open "POST", url,false
     oXMLHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
     oXMLHttp.setRequestHeader "Authorization","Bearer " & skey
     oXMLHttp.send sendstr
     if (oXMLHttp.status = 200) Then
       oJSON.loadJSON(oXMLHttp.responseText)
       response.write oXMLHttp.responseText
     else
       response.write oXMLHttp.responseText
     end if

this is the error received from Stripe

{ "error": { "message": "Invalid array", "param": "items", "type": "invalid_request_error" } }

Before the call to subscription, I create a new customer and gets the new stripecustomerid back fine. Is there anybody who can guide me in writing the right syntax for calling the subscriptions API from Classic ASP?

Note: price_1JZtqEASSxQ8uiR9U5uEZNH9 is created within the stripe dashboard.

user692942
  • 16,398
  • 7
  • 76
  • 175
  • You need to escape your quotes - try `sendstr = "customer=" & stripecustomerid & "&""items[price].[id]=""price_1JZtqEASSxQ8uiR9U5uEZNH9"` should come out as `customer=yourcustomerid&"items[price].[id]"=price_1JZtqEASSxQ8uiR9U5uEZNH9`. – user692942 Sep 16 '21 at 12:16
  • thank you user692942 - your suggestion only makes little change in error description: { "error": { "code": "parameter_unknown", "doc_url": "https://stripe.com/docs/error-codes/parameter-unknown", "message": "Received unknown parameter: \"items. Did you mean items?", "param": "\"items", "type": "invalid_request_error" } } I think the syntax of items[] are wrong but do not know how to write it correct! – Michael Fiil Sep 16 '21 at 12:31
  • 1
    Try using the example in the documentation `items[0][price]`. – user692942 Sep 16 '21 at 12:44
  • thank you user692942 - we are getting there - changing to sendstr = "customer=" & stripecustomerid & "&items[0][price]=price_1JZtqEASSxQ8uiR9U5uEZNH9" now gives an error on customer { "error": { "code": "resource_missing", "doc_url": "https://stripe.com/docs/error-codes/resource-missing", "message": "This customer has no attached payment source or default payment method.", "type": "invalid_request_error" } } so i have do figure out how to add this when creating the customer – Michael Fiil Sep 16 '21 at 13:28
  • thanks for the help - now I have finally found out, the order and specifically that: 1) the first thing to do is complete a checkout (complete a payment and get a token back from stripe) 2) then you can create the customer via api called to / customers / and 3) create a subscription via / subscriptions / this link https://stackoverflow.com/questions/42232827/stripe-custom-checkout-not-posting has given help to 1) and then I am missing the rest, but think good I make it work. Once again thank you :-) – Michael Fiil Sep 17 '21 at 13:43

0 Answers0