Recurring payment extension

Discussion in 'Extensions' started by kofo, Nov 14, 2016.

  1. kofo

    kofo New Member

    Joined:
    Oct 31, 2016
    Messages:
    13
    Likes Received:
    1
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    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
     
  2. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,592
    Likes Received:
    2,460
    @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.
     
  3. kofo

    kofo New Member

    Joined:
    Oct 31, 2016
    Messages:
    13
    Likes Received:
    1
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    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
     
  4. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,592
    Likes Received:
    2,460
    @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($rawBodytrue) : 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)$subscriptiontrue);
            
    $transaction->status                         PricePlanOrderTransaction::STATUS_SUCCESS;
            
    $transaction->save(false);
            
            
    Yii::app()->end();
        }
    }
     
    sendizo likes this.
  5. Niko

    Niko Active Member

    Joined:
    Oct 27, 2015
    Messages:
    198
    Likes Received:
    39
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    5
    Hi @twisted1919 you have in the roadmap the release of recurring payment extension?
     
    sendizo likes this.
  6. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,592
    Likes Received:
    2,460
    @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.
     
    Niko likes this.
  7. Niko

    Niko Active Member

    Joined:
    Oct 27, 2015
    Messages:
    198
    Likes Received:
    39
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    5
    Cool
     
  8. Niko

    Niko Active Member

    Joined:
    Oct 27, 2015
    Messages:
    198
    Likes Received:
    39
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    5
    Is compatible with older version of mwizz?
    1.3.7.2
     
  9. Jakub VYtiska

    Jakub VYtiska New Member

    Joined:
    Feb 22, 2016
    Messages:
    5
    Likes Received:
    2
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    Hi, is this recurring payment extension in store now? i dont see that. Thanks
     
  10. Niko

    Niko Active Member

    Joined:
    Oct 27, 2015
    Messages:
    198
    Likes Received:
    39
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    5
    Not yet...is under review from envato as you can read above
     
  11. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,592
    Likes Received:
    2,460
    >= 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.
     

Share This Page