<p>You'd listen to Charge's <code>onCharge</code> event just like you'd listen to any of Craft's own <a href="https://craftcms.com/docs/plugins/events-reference" rel="nofollow">events</a>, using a <a href="https://craftcms.com/docs/plugins/" rel="nofollow">plugin</a>.</p>

<p>Your plugin's <code>init()</code> method, for example could do this:</p>

<pre><code>craft()-&gt;on('charge.onCharge', function(Event $event) {
    // ...
});
</code></pre>

<p>There's a nifty Craft plugin scaffold generator to get you started <a href="http://pluginfactory.io/" rel="nofollow">here</a>, too.</p>

CC BY-SA 3.0
2016-02-17T17:30:55.487Z
2016-02-17T17:30:55.487Z
Brad Bell
<p>I would like to update a specific entry upon the completion of a successful payment through the charge plugin. For this, <a href="http://squarebit.co.uk/software/craft/charge" rel="nofollow">Charge</a> provides the callback 'charge.onCharge,' as detailed in the <a href="http://squarebit.co.uk/software/craft/charge/usage/hook-events#event-onCharge" rel="nofollow">'Hooks &amp; Events Page'</a> of the documentation.</p>

<p>The issue is that I have no idea where to put PHP code to utilize this callback, nor what this code would look like. Is there an example that would explain exactly how to use the callback, and exactly where the code would go?</p>

<php><hook><plugin-charge>
Where do I put code to use hooks and events from Squarebit's 'Charge' plugin?
# Where do I put code to use hooks and events from Squarebit's 'Charge' plugin?

(Asked by: username_0 on 2016-02-17)

I would like to update a specific entry upon the completion of a successful payment through the charge plugin. For this, [Charge](http://squarebit.co.uk/software/craft/charge) provides the callback 'charge.onCharge,' as detailed in the ['Hooks & Events Page'](http://squarebit.co.uk/software/craft/charge/usage/hook-events#event-onCharge) of the documentation.

The issue is that I have no idea where to put PHP code to utilize this callback, nor what this code would look like. Is there an example that would explain exactly how to use the callback, and exactly where the code would go?

**Tags:** php, hook, plugin-charge


---

## 1 answers

### Answer by username_1 on 2016-02-17. Score: 3 | Accepted answer

You'd listen to Charge's onCharge event just like you'd listen to any of Craft's own events, using a plugin.
Your plugin's init() method, for example could do this:
craft()->on('charge.onCharge', function(Event $event) {
    // ...
});

There's a nifty Craft plugin scaffold generator to get you started here, too.


---

