Base solution for your next web application
Open Closed

Stripe integration - musings #6846


User avatar
0
BobIngham created

I follow instructions here: Stripe Integration I create an account with Stripe and update my appsettings.json:

"Stripe": {
    "IsActive": "true",
    "BaseUrl": "https://api.stripe.com/v1",
    "SecretKey": "sk_test_...",
    "PublishableKey": "pk_test_...",
    "WebhookSecret": ""
}

I create an account at webhooks. I add the Signing secret from the webhooks page to appsettings.json:

"Stripe": {
    "IsActive": "true",
    "BaseUrl": "https://api.stripe.com/v1",
    "SecretKey": "sk_test_...",
    "PublishableKey": "pk_test_...",
    "WebhookSecret": "[secret]"
}

I run my core project and refresh swagger. I download relay-windows-amd64.exe and rename it to "relay.exe". In my command line I run:

relay login -k [key] -s [secret]

and then:

relay forward --bucket stripe http://localhost:22742/Stripe/WebHooks

I receive a url in my command line:

https://my.webhookrelay.com/v1/webhooks/[uniqueidentifier]

I add this url a WebHook endpoint on Stripe's WebHook dashboard (https://dashboard.stripe.com/account/webhooks). I run the dotnetcore project and, in the Stripe web hooks section, I run "Send test webhook" and receive the call at a breakpoint in my StripeController: I check my logs and find the following error message: Received event with API version 2019-03-14, but Stripe.net 24.3.0 expects API version 2019-02-19. We recommend that you create a WebhookEndpoint with this API version. I google this and decide to upgrade the Stripe nuget package to 25.6.0 which removes these errors but I wonder what would happen if Stripe changed their API version whilst the system is in production? I run the angular project on localhost and, from the host sign in page I select "new tenant", select a payment plan and "Buy now", enter tenant details. On the first payment page I check "Automatically bill my account": I select "Checkout with Stripe" and get the following error:

 NullInjectorError: No provider for StripePaymentServiceProxy!


what am I missing?


5 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    Do you have the following line in service-proxy.module.ts?

    @NgModule({
        providers: [
            // ...
            ApiServiceProxies.StripePaymentServiceProxy, // This line
            // ...
        ]
    })
    
  • User Avatar
    0
    BobIngham created

    Hi Aaron, thanks for the speedy reply as always. You are correct, I had missed both the Stripe and Paypal proxies from my service proxy module during the recent merge operation due to upgrade from 5.4.1 to 6.8.0. I was going to update the thread and will do so when testing is complete.

  • User Avatar
    0
    BobIngham created

    Having got this working and played with it for a while I have the following observations:

    Documentation

    The documentation is a little sparse and could be expanded to give an "easy step guide". As it is one has to trawl through the Webhook and Stripe sites to get the exact information needed. That said, it wasn't too difficult.

    Setting up Zero editions

    When setting up an edition there should be no spaces in the name or Stripe will throw the following error:

    This value must match the regex pattern. (/\A[a-zA-Z0-9_\-]+\z/ does not match for the value 5 devices_Monthly_GBP).
    Stripe.StripeException: This value must match the regex pattern. (/\A[a-zA-Z0-9_\-]+\z/ does not match for the value 5 devices_Monthly_GBP).
    

    Where "5 devices" is the name of the edition. I used edition.displayName property to change the name on the pricing page.

    Setting up a Stripe product

    In file [Projectname].Core\MultiTenancy\Payments\Stripe\StripeGatewayManager.cs a product name is defined at line 24:

    public static string ProductName = "_YourProductNameHere _";
    

    I believe, given current code, this will create a new product for in Stripe for every sale. It would be better to create a product in the Stripe portal and then take the generated Id and replace YourProductNameHere (above) with the generated Id. This will ensure all of your sales are for the same Stripe product.

    Financials -tax

    If I am not mistaken there is no functionality for tax. Stripe has the ability to change tax and call it "VAT" with a type of "percentage". I found a way to get Stripe to create a VAT-able invoice by changing the following code in StripeGatewayManager.CreateSubscription():

    var subscriptionService = new SubscriptionService();
    var subscription = await subscriptionService.CreateAsync(new SubscriptionCreateOptions
    {
        CustomerId = customerId,
        Items = new List<SubscriptionItemOption>
            {
                new SubscriptionItemOption
                {
                    PlanId = planId
                }
            }
    });
    

    to:

    var items = new List<SubscriptionItemOption> { new SubscriptionItemOption { PlanId = planId } };
    var options = new SubscriptionCreateOptions
    {
        CustomerId = customerId,
        Items = items,
        TaxPercent = 20
    };
    var service = new SubscriptionService();
    Subscription subscription = service.Create(options);
    

    Example given at Stripe - Applying Taxes to Subscriptions The above change got 20% VAT working with Stripe.

    Financials - host grid

    There should be a transactions grid in the host for invoices and payments for all payment providers.

    Testing

    It is difficult to test. How do I set up a daily or weekly subscription so I can test over a period of days or weeks rather than a period of months? There are very few emails sent by the system to update the relevant users. Zero seems to leave it to Stripe for payment reminders and confirmations. Can anyone suggest a way of testing when Zero enumerators give us Monthly and Annual only?

    Host dashboard

    The host dashboard showed new tenants but did not display financials from test transactions at Stripe. I haven't had time to investigate this in more depth but I was wondering why this would be the case.

    I will continue to investigate and post back here. I will understand if you don't want this feedback, please close the issue and I will update my own documentation only. Thanks go to Aaron, who insisted I read up on forum etiquette.

  • User Avatar
    0
    commondesk created

    Thanks for writing this. I will refer to this when im ready to do stripe intergration. I for one, encourage you to keep adding to this.

    This whole issue about the lack of complete documenation is becoming a BIG problem with ASPNETZERO. Its such an easy fix, i really dont know why they have such a blind spot about it.

    I've also started writing my own documenation. FYI, i have a procedure as to how to use mysql.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @bobingham

    I google this and decide to upgrade the Stripe nuget package to 25.6.0 which removes these errors but I wonder what would happen if Stripe changed their API version whilst the system is in production?

    I believe this is not related to AspNet Zero but Stipe. If they are making such breaking changes, you will have problem even if you are not using AspNet Zero. But, I'm also suprised by such a problem in production environment for a payment gateway.

    @commondesk we will check Stripe documentaion again and improve it.