Esempio n. 1
0
 /**
  * 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);
 }
Esempio n. 2
0
 /**
  * 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);
         }
     }
 }
Esempio n. 3
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. 4
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. 5
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. 6
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;
 }