Skip to content

Instantly share code, notes, and snippets.

@agentcoops
Last active July 28, 2020 02:40
Show Gist options
  • Save agentcoops/45cf61c03756b85aa2d8 to your computer and use it in GitHub Desktop.
Save agentcoops/45cf61c03756b85aa2d8 to your computer and use it in GitHub Desktop.
Dim StripeURL, APIKey
StripeURL = "https://api.stripe.com/v1/charges"
APIKey = <YOUR SECRET KEY>
Function makeStripeAPICall(requestBody)
Dim objXmlHttpMain
Set objXmlHttpMain = CreateObject("Msxml2.ServerXMLHTTP")
On Error Resume Next
objXmlHttpMain.open "POST", StripeURL, False
objXmlHttpMain.setRequestHeader "Authorization", "Bearer "& APIKey
objXmlHttpMain.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objXmlHttpMain.send requestBody
makeStripeAPICall = objXmlHttpMain.responseText
End Function
Function chargeCard(month, year, cvc, number, cost)
Dim cardDetails, requestBody
cardDetails = "source[exp_month]="& month &"&source[exp_year]="& year &"&source[number]="& number &"&source[cvc]="& cvc
requestBody = "currency=usd&amount="& cost &"&source[object]=card&"& cardDetails
chargeCard = makeStripeAPICall(requestBody)
End Function
Function chargeCardWithToken(token, cost)
Dim requestBody
requestBody = "currency=usd&amount="& cost &"&source="& token
chargeCardWithToken = makeStripeAPICall(requestBody)
End Function
MsgBox(chargeCard("01", "20", "123", "4242424242424242", "400"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment