1

I'm trying to use a custom action with Charge. When a successful charge has been made I want to edit a user field. Charge appears to have Actions but little documentation on how they should be used ( http://demos.squarebit.co.uk/charge/actions )

So, I had opened charge/services/Charge_ActionsService.php and created a new one in there, which worked...

private function triggerActionCredits($details, ChargeModel $chargeModel)
{
    craft()->charge_log->action('Credits action triggered successfully');

    if (!is_array($details)) {
        craft()->charge_log->action("Details passed were: $details");
    } else {
        $detailsAsString = print_r($details);
        craft()->charge_log->action("Details passed were: $detailsAsString");
    }

    $userID = $chargeModel->userId;
    $theUser = craft()->users->getUserById($userId);
    $currentCredits = $theUser->creditsAvailable;

    craft()->charge_log->action("Got the user: $theUser");
    craft()->charge_log->action("Current credits: $currentCredits");
    craft()->charge_log->action("Details passed were: $detailsAsString");

    ... do stuff ...

    return true;
}

However, this should really be a plugin - so I've tried to port that code out of the Actions file and into its own plugin as follows:

public function init()
{
    craft()->on('charge.onCharge', function($charge){
        craft()->charge_log->action('Credits action triggered successfully');

        $pounds = $charge->amount;
        ...
}

The problem is that the line $pounds = $charge->amount; is throwing an error:

Property "Craft\Event.amount" is not defined

But; the event should be getting a Charge model? What am I doing wrong? http://squarebit.co.uk/software/craft/charge/usage/developer/hooks-and-events & http://squarebit.co.uk/software/craft/charge/usage/models/charge-model

2

You want something like this:

craft()->on('charge.onCharge', function($event)
{
    $charge = $event->params['charge'];

    $pounds = $charge->amount;
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.