コード例 #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);
 }
コード例 #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);
         }
     }
 }
コード例 #3
0
ファイル: ChargeManager.php プロジェクト: adrx/stripe-bundle
 /**
  * {@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;
 }
コード例 #4
0
ファイル: InvoiceManager.php プロジェクト: adrx/stripe-bundle
 /**
  * {@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;
 }
コード例 #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;
 }
コード例 #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;
 }