Esempio n. 1
0
 /**
  * Handle card delete event
  *
  * @param StripeEventType $event
  *
  * @throws StripeException
  */
 public function onCardDeleteEvent(StripeEventType $event)
 {
     $stripeCard = $event->getEvent()['data']['object'];
     if ($stripeCard['object'] != StripeCard::STRIPE_OBJECT) {
         throw new StripeException(sprintf('Invalid object type "%s". Expected type is "%s".', $stripeCard['object'], StripeCard::STRIPE_OBJECT));
     }
     $this->cardManager->remove($stripeCard, true);
 }
 /**
  * Handle invoice events
  *
  * @param StripeEventType $event
  * @throws StripeException
  */
 public function onInvoiceEvent(StripeEventType $event)
 {
     $stripeInvoice = $event->getEvent()['data']['object'];
     if ($stripeInvoice['object'] != StripeInvoice::STRIPE_OBJECT) {
         throw new StripeException(sprintf('Invalid object type "%s". Expected type is "%s".', $stripeInvoice['object'], StripeInvoice::STRIPE_OBJECT));
     }
     $this->invoiceManager->save($stripeInvoice, true);
 }
 /**
  * Handle subscription delete event
  *
  * @param StripeEventType $event
  *
  * @throws StripeException
  */
 public function onSubscriptionDeleteEvent(StripeEventType $event)
 {
     $stripeSubscription = $event->getEvent()['data']['object'];
     if ($stripeSubscription['object'] != StripeSubscription::STRIPE_OBJECT) {
         throw new StripeException(sprintf('Invalid object type "%s". Expected type is "%s".', $stripeSubscription['object'], StripeSubscription::STRIPE_OBJECT));
     }
     $this->subscriptionManager->remove($stripeSubscription['id'], true);
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function save(StripeObject $stripeObject, $flush = false)
 {
     /** @var ChargeModelInterface $charge */
     $charge = parent::save($stripeObject);
     if ($stripeObject['source']) {
         /** @var CardModelInterface $card */
         $card = $this->cardManager->save($stripeObject['source'], $flush);
         $charge->setSource($card->getStripeId());
     }
     if ($flush) {
         $this->objectManager->flush($charge);
     }
     return $charge;
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function save(StripeObject $stripeObject, $flush = false)
 {
     /** @var InvoiceModelInterface $invoice */
     $invoice = parent::save($stripeObject);
     if ($stripeObject['discount']) {
         /** @var CouponModelInterface $coupon */
         $coupon = $this->couponManager->save($stripeObject['discount']['coupon'], $flush);
         $invoice->setCoupon($coupon->getStripeId());
     }
     if ($flush) {
         $this->objectManager->flush($invoice);
     }
     return $invoice;
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function save(StripeObject $stripeObject, $flush = false)
 {
     $model = parent::save($stripeObject, $flush);
     if ($stripeObject['sources']['total_count'] > 0) {
         foreach ($stripeObject['sources']['data'] as $sourceObject) {
             $this->cardManager->save($sourceObject, $flush);
         }
     }
     if ($stripeObject['subscriptions']['total_count'] > 0) {
         foreach ($stripeObject['subscriptions']['data'] as $subscriptionObject) {
             $this->subscriptionManager->save($subscriptionObject, $flush);
         }
     }
     return $model;
 }
Esempio n. 7
0
 /**
  * @inheritdoc
  */
 public function save(StripeObject $stripeObject, $flush = false)
 {
     /** @var SubscriptionModelInterface $subscription */
     $subscription = parent::save($stripeObject);
     if ($stripeObject['discount']) {
         /** @var CouponModelInterface $coupon */
         $coupon = $this->couponManager->save($stripeObject['discount']['coupon'], $flush);
         $subscription->setCoupon($coupon->getStripeId());
     }
     if ($stripeObject['plan']) {
         /** @var PlanModelInterface $plan */
         $plan = $this->planManager->save($stripeObject['plan'], $flush);
         $subscription->setPlan($plan->getStripeId());
     }
     if ($flush) {
         $this->objectManager->flush($subscription);
     }
     return $subscription;
 }
Esempio n. 8
0
 /**
  * Handle customer discount remove action
  *
  * @param StripeEventType $event
  *
  * @throws StripeException
  */
 public function onCustomerDiscountDeleteEvent(StripeEventType $event)
 {
     $stripeDiscount = $event->getEvent()['data']['object'];
     $this->validateEventObject($stripeDiscount, StripeDiscount::STRIPE_OBJECT);
     /** @var CustomerModelInterface $customer */
     if ($customer = $this->customerManager->retrieve($stripeDiscount['customer'])) {
         if ($customer->getCoupon() == ${$stripeDiscount}['coupon']['id']) {
             $customer->setCoupon(null);
             $this->objectManager->flush($customer);
         }
     }
 }