Skip to content

Commit

Permalink
Updated for billing
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Ogilvie committed Nov 17, 2019
1 parent 7c9ba91 commit c481ce8
Show file tree
Hide file tree
Showing 14 changed files with 711 additions and 29 deletions.
40 changes: 22 additions & 18 deletions Controller/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Miracode\StripeBundle\Stripe\StripeObjectType;
use Miracode\StripeBundle\StripeException;
use Stripe\Error\SignatureVerification;
use Stripe\Exception\SignatureVerificationException;
use Stripe\Webhook;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -40,24 +41,27 @@ public function handleAction(Request $request)

// Secure webhook with event signature: https://stripe.com/docs/webhooks/signatures
$webhookSecret = $this->getParameter('miracode_stripe.webhook_secret');
// if($webhookSecret !== null) {
// $sigHeader = $request->headers->get('Stripe-Signature');
// try {
// $event = Webhook::constructEvent(
// $request->getContent(), $sigHeader, $webhookSecret
// );
// } catch(\UnexpectedValueException $e) {
// // Invalid payload
// throw new StripeException(
// sprintf('Invalid event payload', $requestData->id)
// );
// } catch(SignatureVerification $e) {
// // Invalid signature
// throw new StripeException(
// sprintf('Invalid event signature', $requestData->id)
// );
// }
// }

$verifySignature = $this->getParameter('verify_stripe_signature');

if($verifySignature === true && $webhookSecret !== null) {
$sigHeader = $request->headers->get('Stripe-Signature');
try {
$event = Webhook::constructEvent(
$request->getContent(), $sigHeader, $webhookSecret
);
} catch(\UnexpectedValueException $e) {
// Invalid payload
throw new StripeException(
sprintf('Invalid event payload', $requestData->id)
);
} catch(SignatureVerificationException $e) {
// Invalid signature
throw new StripeException(
sprintf('Invalid event signature', $requestData->id)
);
}
}

$stripeEventApi = new StripeEventApi();

Expand Down
2 changes: 2 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ public function getConfigTreeBuilder()
->scalarNode('charge')->cannotBeEmpty()->end()
->scalarNode('coupon')->cannotBeEmpty()->end()
->scalarNode('customer')->cannotBeEmpty()->end()
->scalarNode('tax_id')->cannotBeEmpty()->end()
->scalarNode('discount')->cannotBeEmpty()->end()
->scalarNode('invoice')->cannotBeEmpty()->end()
->scalarNode('product')->cannotBeEmpty()->end()
->scalarNode('plan')->cannotBeEmpty()->end()
->scalarNode('refund')->cannotBeEmpty()->end()
->scalarNode('subscription')->cannotBeEmpty()->end()
->scalarNode('subscription_item')->cannotBeEmpty()->end()
->scalarNode('tax_rate')->cannotBeEmpty()->end()
->end()
->end()
->end()
Expand Down
9 changes: 8 additions & 1 deletion Event/StripeEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ class StripeEvent extends Event
const CUSTOMER_SUBSCRIPTION_CREATED = 'stripe.customer.subscription.created';
const CUSTOMER_SUBSCRIPTION_DELETED = 'stripe.customer.subscription.deleted';
const CUSTOMER_SUBSCRIPTION_UPDATED = 'stripe.customer.subscription.updated';
const CUSTOMER_SUBSCRIPTION_TRAIL_WILL_END = 'stripe.customer.subscription.trial_will_end';
const CUSTOMER_SUBSCRIPTION_TRIAL_WILL_END = 'stripe.customer.subscription.trial_will_end';
const CUSTOMER_TAX_ID_CREATED = 'stripe.customer.tax_id.created';
const CUSTOMER_TAX_ID_UPDATED = 'stripe.customer.tax_id.updated';
const INVOICE_CREATED = 'stripe.invoice.created';
const INVOICE_DELETED = 'stripe.invoice.deleted';
const INVOICE_FINALIZED = 'stripe.invoice.finalized';
const INVOICE_ITEM_UPDATED = 'stripe.invoiceitem.updated';
const INVOICE_PAYMENT_ACTION_REQUIRED = 'stripe.invoice.payment_action_required';
const INVOICE_PAYMENT_FAILED = 'stripe.invoice.payment_failed';
const INVOICE_PAYMENT_SUCCEEDED = 'stripe.invoice.payment_succeeded';
const INVOICE_SENT = 'stripe.invoice.sent';
Expand All @@ -41,9 +45,12 @@ class StripeEvent extends Event
const PLAN_CREATED = 'stripe.plan.created';
const PLAN_DELETED = 'stripe.plan.deleted';
const PLAN_UPDATED = 'stripe.plan.updated';
const PAYMENT_INTENT_SUCCEEDED = 'stripe.payment_intent.succeeded';
const SOURCE_CANCELED = 'stripe.source.canceled';
const SOURCE_CHARGEABLE = 'stripe.source.chargeable';
const SOURCE_FAILED = 'stripe.source.failed';
const TAX_RATE_CREATED = 'stripe.tax_rate.created';
const TAX_RATE_UPDATED = 'stripe.tax_rate.updated';

/**
* @var StripeObject
Expand Down
10 changes: 7 additions & 3 deletions EventListener/StripeEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ public static function getSubscribedEvents()
StripeEvent::CHARGE_REFUNDED => 'onStripeChargeEvent',
StripeEvent::CHARGE_SUCCEEDED => 'onStripeChargeEvent',
StripeEvent::CHARGE_UPDATED => 'onStripeChargeEvent',

StripeEvent::COUPON_CREATED => 'onStripeEvent',
StripeEvent::COUPON_UPDATED => 'onStripeEvent',
StripeEvent::CUSTOMER_CREATED => 'onStripeEvent',
StripeEvent::CUSTOMER_UPDATED => 'onStripeEvent',
StripeEvent::CUSTOMER_TAX_ID_CREATED => 'onStripeEvent',
StripeEvent::CUSTOMER_TAX_ID_UPDATED => 'onStripeEvent',
StripeEvent::CUSTOMER_SOURCE_CREATED => 'onStripeEvent',
StripeEvent::CUSTOMER_SOURCE_UPDATED => 'onStripeEvent',
StripeEvent::CUSTOMER_SUBSCRIPTION_CREATED => 'onStripeEvent',
StripeEvent::CUSTOMER_SUBSCRIPTION_UPDATED => 'onStripeEvent',
StripeEvent::CUSTOMER_SUBSCRIPTION_TRAIL_WILL_END => 'onStripeEvent',
StripeEvent::CUSTOMER_SUBSCRIPTION_DELETED => 'onStripeEvent',
StripeEvent::CUSTOMER_SUBSCRIPTION_TRIAL_WILL_END => 'onStripeEvent',
StripeEvent::INVOICE_CREATED => 'onStripeEvent',
StripeEvent::INVOICE_FINALIZED => 'onStripeEvent',
StripeEvent::INVOICE_PAYMENT_FAILED => 'onStripeEvent',
Expand All @@ -56,9 +58,10 @@ public static function getSubscribedEvents()
StripeEvent::SOURCE_CANCELED => 'onStripeEvent',
StripeEvent::SOURCE_CHARGEABLE => 'onStripeEvent',
StripeEvent::SOURCE_FAILED => 'onStripeEvent',
StripeEvent::CUSTOMER_SUBSCRIPTION_DELETED => 'onStripeEvent',

StripeEvent::COUPON_DELETED => 'onStripeDeleteEvent',
StripeEvent::TAX_RATE_CREATED => 'onStripeEvent',
StripeEvent::TAX_RATE_UPDATED => 'onStripeEvent',
StripeEvent::CUSTOMER_DELETED => 'onStripeDeleteEvent',
StripeEvent::CUSTOMER_SOURCE_DELETED => 'onStripeDeleteEvent',
StripeEvent::PLAN_DELETED => 'onStripeDeleteEvent',
Expand All @@ -77,6 +80,7 @@ public function onStripeEvent(StripeEvent $event)
}
}


/**
* @param StripeEvent $event
*/
Expand Down
15 changes: 9 additions & 6 deletions Manager/Doctrine/DoctrineORMModelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Miracode\StripeBundle\Model\StripeModelInterface;
use Miracode\StripeBundle\StripeException;
use Miracode\StripeBundle\Transformer\TransformerInterface;
use Stripe\Customer;
use Stripe\StripeObject;

class DoctrineORMModelManager implements ModelManagerInterface
Expand Down Expand Up @@ -212,14 +213,16 @@ protected function createModel(StripeObject $object)
}

// // If the object has a customer then map.
// if($object->customer){
// $class->setCustomer($this->objectManager->find(AbstractCustomerModel::class, $object->customer));
// }
if($object->customer){
// Get local customer;
$customer = $this->objectManager->find($this->modelClasses['customer'], $object->customer);
$class->setCustomer($customer);
}
//
// // If the object has a has a product then map.
// if($object->product){
// $class->setCustomer($this->objectManager->find(AbstractProductModel::class, $object->product));
// }
if($object->product){
$class->setCustomer($this->objectManager->find($this->modelClasses['product'], $object->product));
}

return $class;

Expand Down
31 changes: 31 additions & 0 deletions Model/AbstractCouponModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ abstract class AbstractCouponModel extends StripeModel
*/
protected $created;

/**
* @StripeObjectParam
*
* @var string
*/
protected $name;

/**
* @StripeObjectParam
*
Expand Down Expand Up @@ -329,4 +336,28 @@ public function setValid($valid)

return $this;
}

/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}

/**
* Set Name.
*
* @param string $name
*
* @return AbstractCouponModel
*/
public function setName(string $name): AbstractCouponModel
{
$this->name = $name;

return $this;
}


}
2 changes: 1 addition & 1 deletion Model/AbstractCustomerModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class AbstractCustomerModel extends StripeModel

/**
* @StripeObjectParam(name="default_source")
*
* @deprecated
* @var string
*/
protected $defaultSource;
Expand Down
89 changes: 89 additions & 0 deletions Model/AbstractInvoiceModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ abstract class AbstractInvoiceModel extends StripeModel
*/
protected $subtotal;

/**
* @StripeObjectParam
*
* @var array|null
*/
protected $discount;

/**
* @StripeObjectParam
*
Expand Down Expand Up @@ -237,6 +244,20 @@ abstract class AbstractInvoiceModel extends StripeModel
*/
protected $webhooksDeliveredAt;

/**
* @StripeObjectParam(name="hosted_invoice_url")
*
* @var string
*/
protected $hostedInvoiceUrl;

/**
* @StripeObjectParam(name="invoice_pdf")
*
* @var string
*/
protected $invoicePdf;

/**
* @return int
*/
Expand Down Expand Up @@ -896,4 +917,72 @@ public function setWebhooksDeliveredAt($webhooksDeliveredAt)

return $this;
}

/**
* @return string
*/
public function getHostedInvoiceUrl(): string
{
return $this->hostedInvoiceUrl;
}

/**
* Set HostedInvoiceUrl.
*
* @param string $hostedInvoiceUrl
*
* @return AbstractInvoiceModel
*/
public function setHostedInvoiceUrl(string $hostedInvoiceUrl): AbstractInvoiceModel
{
$this->hostedInvoiceUrl = $hostedInvoiceUrl;

return $this;
}

/**
* @return string
*/
public function getInvoicePdf(): string
{
return $this->invoicePdf;
}

/**
* Set InvoicePdf.
*
* @param string $invoicePdf
*
* @return AbstractInvoiceModel
*/
public function setInvoicePdf(string $invoicePdf): AbstractInvoiceModel
{
$this->invoicePdf = $invoicePdf;

return $this;
}

/**
* @return array|null
*/
public function getDiscount(): ?array
{
return $this->discount;
}

/**
* Set Discount.
*
* @param array|null $discount
*
* @return AbstractInvoiceModel
*/
public function setDiscount(?array $discount): AbstractInvoiceModel
{
$this->discount = $discount;

return $this;
}


}
Loading

0 comments on commit c481ce8

Please sign in to comment.