SQL Server Stripe: Retrieve a Card

Back to Index

Retrieve details about a specific card stored on the customer or recipient.

Documentation: https://stripe.com/docs/api/curl#retrieve_card

CURL Command

curl https://api.stripe.com/v1/customers/cus_CBbg3iRMzWBjoe/sources/card_1BnETKGswQrCoh0Xhu1A6BfL \
   -u STRIPE_SECRET_KEY:

SQL Server Example

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @rest int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    --  URL: https://api.stripe.com/v1/customers/cus_CBbg3iRMzWBjoe/sources/card_1BnETKGswQrCoh0Xhu1A6BfL
    DECLARE @bTls int
    SELECT @bTls = 1
    DECLARE @port int
    SELECT @port = 443
    DECLARE @bAutoReconnect int
    SELECT @bAutoReconnect = 1
    EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'api.stripe.com', STR(@port), STR(@bTls), STR(@bAutoReconnect)
    IF STR(@success) <> 1
      BEGIN

        EXEC sp_OAGetProperty @rest, 'ConnectFailReason', @iTmp0 OUT
        PRINT 'ConnectFailReason: ' + @iTmp0
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        RETURN
      END

    EXEC sp_OAMethod @rest, 'SetAuthBasic', @success OUT, 'STRIPE_SECRET_KEY', ''

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @rest, 'FullRequestNoBodySb', @success OUT, 'GET', '/v1/customers/cus_CBbg3iRMzWBjoe/sources/card_1BnETKGswQrCoh0Xhu1A6BfL', STR(@sbResponseBody)
    IF STR(@success) <> 1
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jsonResponse int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jsonResponse OUT

    EXEC sp_OAMethod @jsonResponse, 'LoadSb', @success OUT, STR(@sbResponseBody)

    DECLARE @id nvarchar(4000)

    DECLARE @object nvarchar(4000)

    DECLARE @address_city int

    DECLARE @address_country int

    DECLARE @address_line1 int

    DECLARE @address_line1_check int

    DECLARE @address_line2 int

    DECLARE @address_state int

    DECLARE @address_zip int

    DECLARE @address_zip_check int

    DECLARE @brand nvarchar(4000)

    DECLARE @country nvarchar(4000)

    DECLARE @customer nvarchar(4000)

    DECLARE @cvc_check int

    DECLARE @dynamic_last4 int

    DECLARE @exp_month int

    DECLARE @exp_year int

    DECLARE @fingerprint nvarchar(4000)

    DECLARE @funding nvarchar(4000)

    DECLARE @last4 nvarchar(4000)

    DECLARE @name int

    DECLARE @tokenization_method int

    EXEC sp_OAMethod @jsonResponse, 'StringOf', @id OUT, 'id'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @object OUT, 'object'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @address_city OUT, 'address_city'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @address_country OUT, 'address_country'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @address_line1 OUT, 'address_line1'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @address_line1_check OUT, 'address_line1_check'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @address_line2 OUT, 'address_line2'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @address_state OUT, 'address_state'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @address_zip OUT, 'address_zip'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @address_zip_check OUT, 'address_zip_check'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @brand OUT, 'brand'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @country OUT, 'country'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @customer OUT, 'customer'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @cvc_check OUT, 'cvc_check'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @dynamic_last4 OUT, 'dynamic_last4'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @exp_month OUT, 'exp_month'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @exp_year OUT, 'exp_year'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @fingerprint OUT, 'fingerprint'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @funding OUT, 'funding'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @last4 OUT, 'last4'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @name OUT, 'name'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @tokenization_method OUT, 'tokenization_method'

    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jsonResponse


END
GO

Sample JSON Response Body

{
  "id": "card_1BnETKGswQrCoh0Xhu1A6BfL",
  "object": "card",
  "address_city": null,
  "address_country": null,
  "address_line1": null,
  "address_line1_check": null,
  "address_line2": null,
  "address_state": null,
  "address_zip": null,
  "address_zip_check": null,
  "brand": "Visa",
  "country": "US",
  "customer": "cus_CBbg3iRMzWBjoe",
  "cvc_check": null,
  "dynamic_last4": null,
  "exp_month": 8,
  "exp_year": 2019,
  "fingerprint": "F9mANtIt1TaukpRJ",
  "funding": "credit",
  "last4": "4242",
  "metadata": {},
  "name": null,
  "tokenization_method": null
}