2017-04-08 8 views
0

私にはコードはありませんが、サブスクリプションの支払いに関する質問があります。 私はサブスクリプションにストライプライブラリを使用し、ユーザのサブスクリプションが期限切れになっているかどうかを知るために、プラットフォームの電子商取引で異なるユーザをアップデートする方法を質問します。 おかげcodeigniterを使用したCron php

答えて

1

あなたはそのためにストライプのウェブフックを使用することができます。

https://stripe.com/docs/webhooks

それはあなたがストライプがあなたのアカウントで起こったイベントを送信したエンドポイントを設定してみます。あなたのケースでは、サブスクリプションステータスがいつpast_dueになるかを知るには、invoice.payment_failedまたはcustomer.subscription.updatedを調べることをお勧めします。またはすべての支払いの再試行が失敗した場合でもcustomer.subscription.deleted

+0

ありがとう、私はこれを試してみたい –

+0

私はウェブサーバー上でCron Jobを使用しません。 –

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で、つまり1か月に顧客を獲得し、アカウントが期限切れになっているかどうかをチェックします。

関連する問題