pedropaf / saas-ecom

Subscription support for ASP.NET MVC 5 apps using Stripe, including out-of-the-box view helpers. Available via NuGET
http://www.saasecom.org
Apache License 2.0
100 stars 41 forks source link

Invoice Paid Webhook Fails #8

Open benfoster opened 9 years ago

benfoster commented 9 years ago

This was when running the MyNotes example. Not sure if it applies to the core code.

BillingAddress is defined as a [ComplexType] which means it has to be initialised (even if it's properties are null). The current code will fail because Invoice.BillingAddress is null:

Null value for non-nullable member. Member: 'BillingAddress'.

I guess (looking at the MyNotes example) that the solution would be to grab the user's current billing address and attach this to the invoice before saving. This would require a way to obtain the User from the Stripe Customer Id. As a temporary fix I did the following:

                case "invoice.payment_succeeded": // Occurs whenever an invoice attempts to be paid, and the payment succeeds.
                    StripeInvoice stripeInvoice = Stripe.Mapper<StripeInvoice>.MapFromJson(stripeEvent.Data.Object.ToString());
                    Invoice invoice = SaasEcom.Core.Infrastructure.Mappers.Map(stripeInvoice);
                    if (invoice != null && invoice.Total > 0)
                    {
                        // TODO get the customer billing address
                        // get the customer billing address
                        // for now we still have to instantiate the address on the invoice
                        invoice.BillingAddress = new BillingAddress();

                        await InvoiceDataService.CreateOrUpdateAsync(invoice);

                        // TODO: Send invoice by email

                    }
                    break;

Personally I'm not a fan of the dependency on ASP.NET Identity and Entity Framework which is why I probably can't use this library. That said, it's a great point of reference!

pedropaf commented 9 years ago

Thanks @benfoster I just added that to the sample, this kind of things probably need to be polished as some people will want different requirements.

By the way, aren't you using EF and Identity for Fabrik? Would you suggest to have SaasEcom.Core coded against a more generic abstraction and add another library that would implement the data layer using EF + Identity but leave it open for other implementations if needed?

benfoster commented 9 years ago

Hey @pedropaf,

No we're using RavenDB and our own hand-rolled identity system. I'm not sure about abstracting the entire data layer but certainly there is no need to be tied to Identity.

Having been working on our own implementation of recurring billing for the past week it seems that the subscriptions domain only crosses the identity system in a few discreet areas. I'd probably go for an ICustomer interface with a few of the SaasEcom required properties (Email, IP Address etc.) then leave it up to the developer to implement it.

By the end of next week I'm hoping to have completed our implementation (against RavenDB). It would be great to meet up after to discuss the experience and see if there's anything I've done that could be contributed to the project.

pedropaf commented 9 years ago

@benfoster that sounds like a plan! let me know when you're done with your implementation and we can catch up and see what can be done. Also, what payment gateway are you using? Stripe? Paypal?

benfoster commented 9 years ago

We're using Paymill currently but switching over to Stripe.

On 3 June 2015 at 10:50, Pedro Alonso notifications@github.com wrote:

@benfoster https://github.com/benfoster that sounds like a plan! let me know when you're done with your implementation and we can catch up and see what can be done. Also, what payment gateway are you using? Stripe? Paypal?

— Reply to this email directly or view it on GitHub https://github.com/pedropaf/saas-ecom/issues/8#issuecomment-108278679.

Ben Foster planetcloud

fabrik. The portfolio and blogging service for creatives. info@getfabrik.com http://getfabrik.com