/** * Handle card events * * @param StripeEventType $event * * @throws StripeException */ public function onCardEvent(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->save($stripeCard, true); }
/** * Handle customer discount events (create/update) * * @param StripeEventType $event * * @throws StripeException */ public function onCustomerDiscountEvent(StripeEventType $event) { $stripeDiscount = $event->getEvent()['data']['object']; $this->validateEventObject($stripeDiscount, StripeDiscount::STRIPE_OBJECT); $coupon = $this->couponManager->save($stripeDiscount['coupon'], true); /** @var CustomerModelInterface $customer */ if ($customer = $this->customerManager->retrieve($stripeDiscount['customer'])) { if ($customer->getCoupon() != $coupon->getStripeId()) { $customer->setCoupon($coupon->getStripeId()); $this->objectManager->flush($customer); } } }
/** * {@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; }
/** * {@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; }
/** * {@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; }
/** * @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; }