Recurring payment extension

kofo

New Member
Hello again mailwizz community,so i'm working on an update for recurring payment on a payment gateway extension i made for my country,so i saw that @twisted1919 created something like that for a payment gateway he did,so i wanted to know how i can get the payment gateway to call back a url on the backend to notify the mailwizz backend that a payment has been made so his quota should be refreshed..thanks again
 
@kofo - in my recurring extension, i have this piece of code:
PHP:
// register the url rule to resolve the extension page.
Yii::app()->urlManager->addRules(array(
    array('ext_stripe_subscriptions_webhooks/index', 'pattern' => 'stripe/webhooks'),
));

// add the backend controller
Yii::app()->controllerMap['ext_stripe_subscriptions_webhooks'] = array(
    'class'     => $this->extension->getPathAlias('frontend.controllers.ExtStripeSubscriptionsWebhooksController'),
    'extension' => $this->extension,
);
So basically anyone hitting the http://www.domain.co/index.php/stripe/webhooks will instantiate the ExtStripeSubscriptionsWebhooksController controller which is located inside the extension, and that will take proper actions.
 
yes i understand that @twisted1919 but how can i get the controller to 1) create an order for the customer email 2)complete the transaction and complete the order....basically if you can just show me a sample code to create an order for a customer using an email and price plan
 
@kofo - i can show you the controller i have:
PHP:
class ExtStripeSubscriptionsWebhooksController extends Controller
{
    /**
     * @var PaymentGatewayStripeSubscriptionsExt
     */
    public $extension;
    
    /**
     * Default action.
     */
    public function actionIndex()
    {
        $rawBody = Yii::app()->request->getRawBody();
        $data    = !empty($rawBody) ? @json_decode($rawBody, true) : null;
        
        if (empty($data) || empty($data['data']) || 
            empty($data['data']['object']['customer']) || 
            empty($data['data']['object']['subscription']) || 
            empty($data['data']['object']['paid']) || 
            empty($data['type']) || $data['type'] != 'invoice.payment_succeeded') {
            return;
        }
        
        \Stripe\Stripe::setApiKey($this->extension->getExtModel()->getSecretKey());
        
        try {
            $stripeCustomer = \Stripe\Customer::retrieve($data['data']['object']['customer']);
            $subscription   = $stripeCustomer->subscriptions->retrieve($data['data']['object']['subscription']);
        } catch (Exception $e) {
            Yii::log($e->getMessage(), CLogger::LEVEL_ERROR);
            return;
        }

        $order = PricePlanOrder::model()->findByAttributes(array(
            'customer_id' => $subscription->metadata->customer_id,
            'order_id'    => $subscription->metadata->order_id,
            'status'      => PricePlanOrder::STATUS_INCOMPLETE,
        ));
        
        if (!empty($order)) {
            $order->status = PricePlanOrder::STATUS_COMPLETE;
            $order->save(false);
            return;
        }
        
        $order = new PricePlanOrder();
        foreach ($subscription->metadata as $key => $value) {
            if ($order->hasAttribute($key)) {
                $order->setAttribute($key, $value);
            }
        }
        $order->order_id = $order->date_added = $order->last_updated = null;
        $order->status = PricePlanOrder::STATUS_COMPLETE;
        $order->save(false);

        $transaction = new PricePlanOrderTransaction();
        $transaction->order_id                       = $order->order_id;
        $transaction->payment_gateway_name           = 'Stripe Subscriptions - www.stripe.com';
        $transaction->payment_gateway_transaction_id = $subscription->id;
        $transaction->payment_gateway_response       = print_r((array)$subscription, true);
        $transaction->status                         = PricePlanOrderTransaction::STATUS_SUCCESS;
        $transaction->save(false);
        
        Yii::app()->end();
    }
}
 
@Niko - It's in the review queue as we speak, will take a few days to get approved but you'll then see it in your Store area from mailwizz.
 
Is compatible with older version of mwizz?
1.3.7.2
>= 1.3.7.3 but that's just because of the design. if you open the extension and modify the minimum requirement to 1.3.7.2 it will work, it's just it will look a bit distinct.
 
Back
Top