Stripe Card Functions

Update 3/20/17: For new accounts, Stripe is requiring TLS 1.2. The CURL library I’m using to talk with Stripe appears to support only TLS 1.1. Until this is figured out, StripeX will NOT work with new Stripe accounts. It continues to work with OLD Stripe accounts. Sorry for any trouble. Hopefully I can track down a solution.


I’ve released a new version of StripeX on VFPXThis version adds several Card functions that allow you to save a credit card to a customer. This is handy for setting up subscription (which I’ll be adding next to StripeX) or if you need to routinely charge a card for a customer. The new methods are:

CardCreate() – Adds a credit card to a customer
CardDelete() – Deletes a credit card from a customer
CardLIst() – Builds a cursor of all the credit cards on the customer
CardRetrieve() – Retrieves information for a particular card

ObjectExtract() – Is a new utility method that retrieves a value from Stripe objects. You can use that, for example, to retrieve the information from the CardRetrieve() method

Here’s some sample code using those functions. It creates a new card for a customer, gets a list of existing cards, retrieves the first card found, prints some info for that card, and then deletes the card that was added card.

local o
o = NEWOBJECT("StripeX")
o.cAPIKey = "YourAPIKeyHere" && test secret
IF !o.Authenticate() && Make sure Stripe working
?"Auth", "Failed", o.cErrorMessage
* Get a customer
LOCAL lCustomer
lCustomer = "YourCustomerIDHere"
?"Load Customer ID: " + o.Customer(lCustomer)
* Add a card
LOCAL lCardAddedID
lCardAddedID = o.CardCreate(lCustomer, "4242424242424242", "0917", "123") && Test card
?"Card Create ID: " + lCardAddedID
* Get a list of cards for the customer
LOCAL lNumberCards
lNumberCards = o.CardList(lCustomer)
?"Cards found for customer: " + TRANSFORM(lNumberCards)
if lNumberCards > 0
LOCAL lCount
lCOunt = 0
SELECT CurStripeCard
lCount = lCount + 1
?" ID for Card #" + TRANSFORM(lCount) + ": " + CurStripeCard.ID
* Retrieve a card, show some info
SELECT CurStripeCard
GO top
?"Retrieve info card #1"
o.CardRetrieve(lCustomer, CurStripeCard.ID)
?" id = ", o.ObjectExtract("id", o.cData)
?" address_City = ", o.objectExtract("address_city", o.cData)
?" last4 = ", o.objectExtract("last4", o.cData)
* Delete the card we added above.
?"Delete card: ", o.CardDelete(lCustomer, lCardAddedID)

view raw
hosted with ❤ by GitHub


2 thoughts on “Stripe Card Functions

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s