Hooks & Events

If you're building a large site and using Charge as part of your payment process sometimes you'll need to add your own custom logic to certain parts of the process. Charge helps you by exposing a few hooks and events for you to trigger your own custom logic against.

Events #

The following hooks are available as part of Charge :

charge.onCharge
Fired as soon as a payment successfully completes
charge.onBeforeCharge
Fired just before a charge is attempted

charge.onCharge #

Fires as soon as a payment successfully completes. Recieves a ChargeModel object containing all the details of the transaction, including populated Stripe response data.

Parameters

charge ChargeModel
The full populated model for the just processed charge payment. Includes all populated Stripe information and keys.

Usage

Usage of the event is a standard Craft event. In your main plugin class' init function you might have this :

craft()->on('charge.onCharge', function (Event $event) {
    $chargeModel = $event->params['charge'];
    //.. add your custom usage of the charge model
});

charge.onBeforeCharge #

Fires just before a charge is attempted. Includes the ChargeModel object containing all the details of the payment about to be attempted.

Parameters

charge ChargeModel
The partially populated model for the payment about to be attempted.

Usage

Usage of the event is a standard Craft event. In your main plugin class' init function you might have this :

craft()->on('charge.onBeforeCharge', function (Event $event) {
    $chargeModel = $event->params['charge'];
    //.. add your custom usage of the charge model
});

Need a hook or event that's not listed here? Just get in touch.