Base solution for your next web application
Open Closed

Stripe Integration #4386


User avatar
0
poolman created

Hello all!

I have seen many people post about wanting an automatic recurring payment integration. We built one in ANZ using Stripe that allows for a choice between using Stripe and PayPal that is currently provided. Since I work for a startup, we decided to share some of our code and experience in doing this with the ANZ community (hopefully some other startups). Over the next few days I will post the code we used to make this happen.

We are currently using ANZ version 5.0.4 jQuery & MVC (seems to work with Core and 4.6.1). We have not done any work with the angular version. We have also switched our setup to use MySQL, so if you see code related to that it can be safely ignored (we will try to pull it out when posting).

We also assume you know how to set up a Stripe account, and therefore we will not cover that.

Please note: While we have spent some time working on this project, it is not yet in use on our production system. It seems to work, but there might be a few bugs floating around that we have not found yet. Since we are being nice enough to share our code with the community, if you find a bug please let us know. :D


4 Answer(s)
  • User Avatar
    0
    poolman created

    <ins>First few steps:</ins>

    Using NuGet Package Manager install Stripe.net on the <ins>Core</ins> project We are using version 11.9.0

    Adjust <ins>Web.Mvc</ins> Startup.cs to add StripeConfiguration

    using Stripe;
    ...
    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
          ...
          //Recaptcha
          services.AddRecaptcha(new RecaptchaOptions
          {
                SiteKey = _appConfiguration["Recaptcha:SiteKey"],
                SecretKey = _appConfiguration["Recaptcha:SecretKey"]
          });
    
          StripeConfiguration.SetApiKey(_appConfiguration["Payment:Stripe:ClientSecret"]);
    
          ...
    }
    

    Adjust <ins>Web.Mvc</ins> appsettings.json to allow for storage of keys You will add a section for Stripe under the Payment section. It will include a ClientId and a ClientSecret.

    "Payment": {
        "PayPal": {
          "Environment": "sandbox",
          "BaseUrl": "https://api.sandbox.paypal.com/v1",
          "ClientId": "",
          "ClientSecret": "",
          "DemoUsername": "",
          "DemoPassword": ""
        },
        "Stripe": {
          "Environment": "sandbox",
          "ClientId": "<REPLACE>",
          "ClientSecret": "<REPLACE>"
        }
      }
    

    Add to <ins>Core</ins> a MultiTenancy/Payments/Stripe/StripeConfiguration.cs

    namespace WD2c.MultiTenancy.Payments.Stripe
    {
        public class StripeConfiguration : ITransientDependency
        {
            private readonly IConfigurationRoot _appConfiguration;
    
            public string Environment => _appConfiguration["Payment:Stripe:Environment"];
    
            public string ClientId => _appConfiguration["Payment:Stripe:ClientId"];
    
            public string ClientSecret => _appConfiguration["Payment:Stripe:ClientSecret"];
    
            public StripeConfiguration(IAppConfigurationAccessor configurationAccessor)
            {
                _appConfiguration = configurationAccessor.Configuration;
            }
        }
    }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks a lot @poolman , it is really appriciated. I'm sure you will get more questions :).

  • User Avatar
    0
    vladsd created

    Thanks for sharing. Do you plan to add client code as well?

  • User Avatar
    0
    alper created
    Support Team

    Thanks @poolman! some folks are excited for recurrent payment. I see that you get some credit card number from client. Do you implement the PCI Data Security Standard (PCI DSS) that applies to all entities that store, process, and/or transmit cardholder data?