2017-04-08 47 views
0

我沒有代碼,但我有訂閱付款的問題。 我使用條紋庫進行訂閱,我的問題是如何更新平臺電子商務中的不同用戶,以瞭解用戶訂閱是否已過期? 感謝Cron php與codeigniter

回答

1

可以使用條紋網絡掛接爲:

https://stripe.com/docs/webhooks

這將讓你建立一個端點,其中條紋會送您事件在您的帳戶中發生的事情。在你的情況下,你想看看invoice.payment_failedcustomer.subscription.updated知道何時訂閱狀態變成past_due。甚至在所有付款重試失敗時甚至可以撥打customer.subscription.deleted

+0

謝謝,我想試試這 –

+0

所以,我不使用Web服務器上的Cron作業,但條紋webhooks。 –

0

我的訂閱條紋

public function checkout(){ 
     $userid = $this->session->userdata('userid'); 
     $email = $this->input->post('email'); 
     $token = $this->input->post('stripeToken'); 
     try { 

      $customer = \Stripe\Customer::create(array(
       "email" => $email, 
       "source" => $token, 
       "description" => "Abonnement" 
      )); 

      $subscription = \Stripe\Subscription::create(array(
       "customer" => $customer->id, 
       "plan" => "premium", 
      )); 

      $invoice = \Stripe\Invoiceitem::create(array(
        "customer" => $customer->id, 
        "amount" => 2000, 
        "currency" => "eur", 
        "description" => "Abonnement", 
      )); 

      // data captured 
      $data = array(
       'id_user' => $userid , 
       'prix_abon' => 20, 
       'date_abon' => date('Y-m-d H:i:s'), 
       'date_suspension' => date('Y-m-d H:i:s'), 
       'etat_abon' => 1, 
       'subscribe_id' => $subscription->id, 
       'customer_id' => $customer->id 

      ); 
      $response = $this->md_abonnement->add($data); 
      if ($response) { 
       $this->sms .= "$.Notification.autoHideNotify('custom', 'top right', 'Abonnement effectué')"; 
       $this->session->set_userdata('controller_message', $this->sms); 
       redirect($_SERVER['HTTP_REFERER'],"refresh"); 
       print_r($customer->id); 
       print_r($subscription->id); 
      } else { 
       $this->sms .= "$.Notification.autoHideNotify('error', 'top right', 'Une erreur est survenu durant votre abonnement', 'Veuillez bien vérifier vos informations')"; 
       $this->session->set_userdata('controller_message', $this->sms); 
       redirect($_SERVER['HTTP_REFERER'],"refresh"); 
      } 

     } catch (Stripe_CardError $e) { 
      echo json_encode(array('status' => 500, 'error' => STRIPE_FAILED)); 
      exit(); 
     } 
} 

代碼的代碼,我試試這個代碼,並已經。我的問題是與webhook即每月捕獲客戶,並檢查他們的帳戶是否過期