This module provides a simple abstraction to use the Stripe PHP SDK. This
module is designed to be required by other contrib/custom modules.

Dependencies

Installation

  • Once the dependencies are in place, install this module using the official
    Backdrop CMS instructions
    .
  • Configure the module at Configuration > Web Services > Stripe
    (admin/config/services/stripe_api), adding your Stripe API keys and
    setting preferences.

Usage

The main way to make Stripe API calls is using the stripe_api_call function.

/**
 * Makes a call to the Stripe API.
 *
 * @param string $obj
 *   Stripe object. Can be a Charge, Refund, Customer, Subscription, Card, Plan,
 *   Coupon, Discount, Invoice, InvoiceItem, Dispute, Transfer, TransferReversal,
 *   Recipient, BankAccount, ApplicationFee, FeeRefund, Account, Balance, Event,
 *   Token, BitcoinReceiver, FileUpload.
 *
 * @param string $method
 *   Stripe object method. Common operations include retrieve, all, create,
 *
 * @param mixed $params
 *   Additional params to pass to the method. Can be an array, string.
 *
 * @return Stripe\ApiResource
 *   Returns the ApiResource or NULL on error.
 */
stripe_api_call($obj, $method = NULL, $params = NULL) { ... }

// Examples.

// Get a customer object.
$customer = stripe_api_call('customer', 'retrieve', 'cus_id123123123');
$customer->email = NEW_EMAIL;
$customer->save();

// Create a customer object.
$customer = stripe_api_call('customer', 'create', array(
  'email' => $user->mail,
));

// Delete a customer.
$customer = stripe_api_call('customer', 'retrieve', 'cus_id123123123');
$customer->delete();

// List customers.
$list = stripe_api_call('customer', 'all', array('limit' => 5));

This module provides a secure Stripe webhook (events are validated) and provides
two hooks for you to implement in your custom module.

/**
 * Interact with all incoming Stripe webhooks.
 *
 * @param string $type
 *   Webhook type, such as customer.created, charge.captured, etc.
 *
 * @param object $data
 *   Incoming data object.
 *
 * @param Stripe\Event $event
 *   The verified Stripe Event that is being sent.
 *   Only available in live mode with real events (not test events).
 *
 * @throws \Exception
 */
function hook_stripe_api_webhook($type, $data, Stripe\Event $event = NULL) { ... }

/**
 * Interact with a specific incoming webhook type.
 *
 * @param object $data
 *   Incoming data object.
 *
 * @param Stripe\Event $event
 *   The verified Stripe Event that is being sent.
 *   Only available in live mode with real events (not test events).
 *
 * @throws \Exception
 */
function hook_stripe_api_webhook_EVENT_TYPE($data, Stripe\Event $event = NULL) { ... }

This is an unofficial module and is no way associated with Stripe.

Issues

Bugs and Feature requests should be reported in this module's
Issue Queue.

License

This project is GPL v2 software. See the LICENSE.txt file in this directory for
complete text.

Current Maintainers

Credits