All Projects → jcberquist → Stripe Cfml

jcberquist / Stripe Cfml

Licence: mit
stripe-cfml is a CFML (Lucee and ColdFusion) library for interacting with the Stripe API.

Projects that are alternatives of or similar to Stripe Cfml

Lucee Aws
Lucee extension to provide simpler access to common AWS commands through the AWS SDK
Stars: ✭ 24 (-52.94%)
Mutual labels:  coldfusion
Combine
Serves Combined & compressed js & css with caching, using ColdFusion
Stars: ✭ 11 (-78.43%)
Mutual labels:  coldfusion
Poiutility.cfc
A ColdFusion component (and set of custom tags) for reading and writing XLS (Excel) documents in ColdFusion.
Stars: ✭ 36 (-29.41%)
Mutual labels:  coldfusion
Cfeosocial
cfeoSocial is a set of gateways/test pages to integrate with Social Media APIs (Google,LinkedIn,Facebook).
Stars: ✭ 8 (-84.31%)
Mutual labels:  coldfusion
Mobilemura
MobileMura is a plugin that adds advanced mobile features to Mura CMS.
Stars: ✭ 9 (-82.35%)
Mutual labels:  coldfusion
Tinytest
A tiny unit testing framework built as a means to learn more about unit testing in ColdFusion.
Stars: ✭ 13 (-74.51%)
Mutual labels:  coldfusion
Birthdayreminder v0.2.0
Stars: ✭ 5 (-90.2%)
Mutual labels:  coldfusion
Colddoc
ColdDoc is a tool that has been built to generate documentation based on ColdFusion Component Meta Data.
Stars: ✭ 44 (-13.73%)
Mutual labels:  coldfusion
Cfmlstats
Parses your CFML code base and gives you stats
Stars: ✭ 10 (-80.39%)
Mutual labels:  coldfusion
Varscoper
varScoper is a code scanning tool that can be used to identify variables that are not explicitly scoped to be local or global to a ColdFusion function.
Stars: ✭ 30 (-41.18%)
Mutual labels:  coldfusion
Forecastcfml
a cfml wrapper for Forecast.io api
Stars: ✭ 8 (-84.31%)
Mutual labels:  coldfusion
Introtogit
Intro to Git presentation materials
Stars: ✭ 9 (-82.35%)
Mutual labels:  coldfusion
Openbd Administrator
The browser based administrator for the Open BlueDragon CFML engine.
Stars: ✭ 14 (-72.55%)
Mutual labels:  coldfusion
Bernoutjethol
Stars: ✭ 8 (-84.31%)
Mutual labels:  coldfusion
Vagrant Lemtl
Vagrant box with Linux, Nginx, MariaDB (or MySQL), Tomcat, and Lucee for local development with CFML and Java
Stars: ✭ 41 (-19.61%)
Mutual labels:  coldfusion
Db Dot Cfc
Enhances cfquery by analyzing SQL to enforce security & framework conventions.
Stars: ✭ 5 (-90.2%)
Mutual labels:  coldfusion
Toscript
Converts Tag based CFML to CFML Script
Stars: ✭ 12 (-76.47%)
Mutual labels:  coldfusion
Validatethis
An object oriented validation framework for ColdFusion objects
Stars: ✭ 45 (-11.76%)
Mutual labels:  coldfusion
Fusebox Coldfusion
Fusebox is a free, easy to use framework for web development that organizes your code for fewer development bugs and faster maintenance. It has a low runtime overhead. It is mainly targeted to ColdFusion but also has versions for PHP and ASP.
Stars: ✭ 41 (-19.61%)
Mutual labels:  coldfusion
Cfbackport
Back porting features contained in newer versions of ColdFusion.
Stars: ✭ 27 (-47.06%)
Mutual labels:  coldfusion

stripe-cfml

stripe-cfml is a CFML (Lucee and ColdFusion) library for interacting with the Stripe API.

Installation

This wrapper can be installed as standalone library or as a ColdBox Module. Either approach requires a simple CommandBox command:

$ box install stripecfml

Alternatively the git repository can be cloned into the desired directory.

Standalone Usage

Once the library has been installed, the core stripe component can be instantiated directly:

stripe = new path.to.stripecfml.stripe(
    apiKey = '',
    config = {}
);

ColdBox Module

To use the library as a ColdBox Module, add the init arguments to the moduleSettings struct in config/Coldbox.cfc:

moduleSettings = {
    stripecfml: {
        apiKey: '',
        config: {}
    }
}

You can then leverage the library via the injection DSL: [email protected]:

property name="stripe" inject="[email protected]";

Note: You can bypass the init arguments altogether and use Java system properties or environment variables to configure stripe-cfml. See Configuration via environment variables and system properties below.

Getting Started

// To charge $20 to a card for which a card token has been created
charge = stripe.charges.create({amount: 2000, currency: 'usd', source: cardToken});
// OR
charge = stripe.charges.create(amount = 2000, currency = 'usd', source = cardToken);

// charge is a struct which can be inspected for the result of the create charge api call
writeDump(charge);

stripe-cfml is modeled after the official Stripe SDKs. In particular it copies the class and method names used in the Node SDK. The Node examples given in the official Stripe documentation are simply able to be copied and used (with the notable difference that this library does not make use of callbacks - everything is done synchronously). However, since CFML supports named arguments, you can also use named arguments instead of passing the arguments in a single struct. The following examples are all valid ways of using this library:

stripe.customers.updateSource('customer_id', 'source_id', {metadata = {'a': 1}});
stripe.customers.updateSource(customer_id = 'customer_id', source_id = 'source_id', params = {metadata: {'a': 1}});
stripe.customers.updateSource(customer_id = 'customer_id', source_id = 'source_id', metadata = {'a': 1});

Note that the customers component and the method name, updateSource, do not change, only the how the arguments are passed to the method. See the reference for more information on the method signatures.

Headers

There are a several arguments you can pass to any method that are passed to the Stripe API as headers: apiKey, stripeVersion (or apiVersion), idempotencyKey, and stripeAccount.

When copying the Node SDK method signatures, headers are passed in a single struct:

charge = stripe.charges.create(
    {amount: 2000, currency: 'usd', source: cardToken},
    {stripeAccount: 'abc', idempotencyKey: 'def'}
);

They can also be passed as named arguments:

charge = stripe.charges.create(
    amount = 2000,
    currency = 'usd',
    source = cardToken,
    stripeAccount = 'abc',
    idempotencyKey = 'def'
);
// OR
charge = stripe.charges.create(
    params = {amount: 2000, currency: 'usd', source: cardToken},
    headers = {stripeAccount: 'abc', idempotencyKey: 'def'}
);

Configuration

You can pass some configuration parameters in a struct to the constructor of stripe.cfc:

config = {
    apiVersion: '',
    defaultCurrency: '',
    convertTimestamps: true,
    convertToCents: false
}
stripe = new stripe('stripe_api_key', config);
  • apiVersion specifies the version of the Stripe API to use - see versioning in the documentation.
  • defaultCurrency specifies the currency to use when making requests (e.g. usd) - when it is specified in the config you do not need to specify it when making requests.
  • convertTimestamps (default: true) - The Stripe API expects all datetimes to be given as Unix timestamps; when this setting is true, stripe-cfml converts all CFML date objects passed into methods to UNIX timestamps and converts timestamps in the API responses back to CFML date objects.
  • convertToCents (default: false) - when this is set to true all currency amounts passed in are multiplied by 100 and all amounts in the responses are divided by 100. (This enables one to work in dollar amounts instead of cents, if so desired.)

Configuration via environment variables and system properties

All of these configuration keys, including the Stripe secret key, can be specified in environment variables or Java system properties instead of being passed in at initialization. When using environment variables your config keys should be prefixed with STRIPE_ and underscores are used to separate words: STRIPE_API_KEY, STRIPE_API_VERSION, STRIPE_DEFAULT_CURRENCY, STRIPE_CONVERT_TIMESTAMPS, and STRIPE_CONVERT_TO_CENTS. When using system properties your config keys should be prefixed with stripe. and all lowercase: stripe.apikey, stripe.apiversion, stripe.defaultcurrency, stripe.converttimestamps, and stripe.converttocents.

Responses

The Stripe API returns a JSON object in response to all HTTP requests (see https://stripe.com/docs/api). stripe-cfml deserializes this object into a CFML struct and makes it available in a response struct under the content key.

Responses to API calls are all returned as structs in the following format:

{
    requestId: ''  // request identifier - see https://stripe.com/docs/api#request_ids
    content: {}    // struct containing the body of the response
    duration: 300  // time the HTTP request took in milliseconds
    headers: {}    // struct containing headers returned by the Stripe API
    status: 200    // status code returned by the Stripe API
}

Webhooks

stripe-cfml can verify signed webhooks received by your server in a similar fashion to the official Stripe SDKs:

try {
    event = stripe.webhooks.constructEvent(webhookJSONPayload, stripeSignatureHeader, endpointSecret);
} catch (any e) {
    // the webhook was not signed properly
}
// otherwise do something with the event

See https://stripe.com/docs/webhooks and https://stripe.com/docs/webhooks/signatures for more information on setting up signed webhooks.

ColdBox Interception Points for Webhooks

ColdBox users can automatically convert incoming webhooks to interception point events. To do this, point Stripe at /stripecfml/webhooks. stripe-cfml will take care of verifying the validity of incoming webhooks and announcing the associated interception point.

Interception Points are a combination of onStripe and the camelCase version of the webhook type. For example, a payment_intent.succeeded type would become a onStripePaymentIntentSucceeded interception point. A full list of interception points can be found in the ModuleConfig.cfc for this module.

To use this feature, you will need to set your endpointSecret in your module settings:

moduleSettings = {
    "stripecfml": {
        "apiKey": getSystemSetting( "STRIPE_API_KEY" ),
        "endpointSecret": getSystemSetting( "STRIPE_ENDPOINT_SECRET" )
    }
};

More information about endpoint secrets can be found on Stripe's website.

This library installs via CommandBox as stripecfml. To fully test the ColdBox functionality of this package, you must clone this repo as stripecfml, e.g. git clone [email protected]:jcberquist/stripe-cfml.git stripecfml.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].