# Stripe Provider Integration

## Stripe

### Installing the integration

* Install the `Ucommerce.Payments.Stripe` NuGet package.
* Add the Stripe integration to the program.cs file to use the default Stripe implementation:

{% code title="Program.cs" %}

```csharp
        services.AddUcommerce()    
            .AddBackOffice()
            .AddPayments()
            .AddStripe()
        
        app.UseUcommerce()
            .UseBackOfficeUi()
            .UsePayments()
            .UseStripe("OptionalCallbackUri");
```

{% endcode %}

{% hint style="warning" %}
`OptionalCallbackUri` is the URI where the Stripe webhook should be pointed to later. If left without a value, the default endpoint will be:`{yourDomain}/Stripe/process/callback`
{% endhint %}

Stripe is now available as a payment method service. It can now be selected for new and existing payment methods.

### Creating a Payment Method

* In the back office UI, navigate to **Settings** -> **Payment Methods.**
* Click *New* to create a new payment method.
* Select *Stripe* as the service.

<figure><img src="https://3923258684-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhumgDG3LdnIYeGE8nt71%2Fuploads%2FxhPS3S3nOX5S3SXYTABH%2FScreenshot%202023-06-08%20112141.png?alt=media&#x26;token=ccc876b9-5967-42cc-88b6-39eaa3a530fc" alt="" width="446"><figcaption><p>All added services will show up in the <em>Service</em> tab</p></figcaption></figure>

### Configuring Stripe

Connect the payment method to a Stripe account by filling out the *Service properties* section in UI.

<figure><img src="https://3923258684-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhumgDG3LdnIYeGE8nt71%2Fuploads%2FLO1fZ2E9O3hnnuH3c6dH%2Fimage%20(3).png?alt=media&#x26;token=62b093c4-d6e1-43fe-a746-35fbf5a882fc" alt="" width="563"><figcaption><p>This is what the default payment service properties looks like - it only contains an <em>AcceptUrl</em> property.</p></figcaption></figure>

{% hint style="info" %}
The service properties available will vary depending on the payment service selected.
{% endhint %}

<table><thead><tr><th>Property</th><th>Description</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>Public Key</td><td>The account-specific public key for the Stripe account. It can be found in the Stripe Developer Dashboard.</td><td>true</td></tr><tr><td>Secret Key</td><td>The account-specific secret key for the Stripe account. It can be found in the Stripe Developer Dashboard.</td><td>true</td></tr><tr><td>Webhook Secret</td><td>The webhook-specific key. It is set up in the Stripe Developer Dashboard.</td><td>true</td></tr><tr><td>Success URL</td><td>The partial route that the user is navigated to on a successful purchase.</td><td>false</td></tr><tr><td>Cancel URL</td><td>The partial route that the user is navigated to on an unsuccessful purchase.</td><td>false</td></tr></tbody></table>

{% hint style="warning" %}
The keys can be found on the Stripe Developer Dashboard located [here](https://dashboard.stripe.com/). When setting up the webhook, remember to point it to the [webhook set on startup](#installing-the-integration).&#x20;
{% endhint %}

Once configured, the payment method can be enabled by flipping the *Enabled* toggle in the UI.

{% hint style="info" %}
When testing the Stripe integration, the [Stripe CLI](https://stripe.com/docs/stripe-cli) can greatly help. If testing is done on a local machine using localhost, a tunneling service can be used as a proxy.
{% endhint %}
