forked from mogilvie/stripe-bundle
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Develop webhook event listeners. Add stripe service wrappers.
- Loading branch information
Showing
30 changed files
with
1,848 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace Aimir\StripeBundle\EventListener; | ||
|
||
use Aimir\StripeBundle\Event\StripeEventType; | ||
use Aimir\StripeBundle\ModelManager\ModelManagerInterface; | ||
use Aimir\StripeBundle\Stripe\StripeCard; | ||
use Aimir\StripeBundle\StripeException; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
class CardEventListener implements EventSubscriberInterface | ||
{ | ||
/** | ||
* @var ModelManagerInterface | ||
*/ | ||
protected $cardManager; | ||
|
||
/** | ||
* CardEventListener constructor. | ||
* | ||
* @param ModelManagerInterface $cardManager | ||
*/ | ||
public function __construct(ModelManagerInterface $cardManager) | ||
{ | ||
$this->cardManager = $cardManager; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
StripeEventType::CUSTOMER_SOURCE_CREATED => 'onCardEvent', | ||
StripeEventType::CUSTOMER_SOURCE_DELETED => 'onCardEvent', | ||
StripeEventType::CUSTOMER_SOURCE_UPDATED => 'onCardEvent', | ||
]; | ||
} | ||
|
||
/** | ||
* 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 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Aimir\StripeBundle\EventListener; | ||
|
||
use Aimir\StripeBundle\Event\StripeEventType; | ||
use Aimir\StripeBundle\ModelManager\ModelManagerInterface; | ||
use Aimir\StripeBundle\Stripe\StripeCharge; | ||
use Aimir\StripeBundle\StripeException; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
class ChargeEventListener implements EventSubscriberInterface | ||
{ | ||
/** | ||
* @var ModelManagerInterface | ||
*/ | ||
protected $chargeManager; | ||
|
||
/** | ||
* CardEventListener constructor. | ||
* | ||
* @param ModelManagerInterface $chargeManager | ||
*/ | ||
public function __construct(ModelManagerInterface $chargeManager) | ||
{ | ||
$this->chargeManager = $chargeManager; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
StripeEventType::CHARGE_CAPTURED => 'onChargeEvent', | ||
StripeEventType::CHARGE_FAILED => 'onChargeEvent', | ||
StripeEventType::CHARGE_REFUNDED => 'onChargeEvent', | ||
StripeEventType::CHARGE_SUCCEEDED => 'onChargeEvent', | ||
StripeEventType::CHARGE_UPDATED => 'onChargeEvent' | ||
]; | ||
} | ||
|
||
/** | ||
* Handle charge events | ||
* | ||
* @param StripeEventType $event | ||
* | ||
* @throws StripeException | ||
*/ | ||
public function onChargeEvent(StripeEventType $event) | ||
{ | ||
$stripeCharge = $event->getEvent()['data']['object']; | ||
if ($stripeCharge['object'] != StripeCharge::STRIPE_OBJECT) { | ||
throw new StripeException(sprintf( | ||
'Invalid object type "%s". Expected type is "%s".', | ||
$stripeCharge['object'], | ||
StripeCharge::STRIPE_OBJECT | ||
)); | ||
} | ||
$this->chargeManager->save($stripeCharge, true); | ||
} | ||
} |
Oops, something went wrong.