# Stripe

## Create customer in stripe based off user UP address

<mark style="color:green;">`POST`</mark> `https://gateway-relay.herokuapp.com/api/stripe/createCustomer`

#### Headers

| Name                                            | Type      | Description                                                                                                                                                                                                                                                                         |
| ----------------------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | jwt token | received via authenticating with the [auth endpoints.](https://karan-khullar.gitbook.io/gateway/documentation/api-reference/auth) **To learn more about the authentication flow, click** [**here**](https://karan-khullar.gitbook.io/gateway/architecture/authentication-flow)**.** |

{% tabs %}
{% tab title="200: OK successful operation" %}
{% code title="Example 200 Response" overflow="wrap" %}

```javascript
{
    walletAddress: '0x218C2BbaaBa0D66ddcD5De942Ed2980Bbfd1f004',
    stripeCustomerId: 'cus_MD1vEjQloWXPQy'
}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized authentication error" %}
{% code title="Example 401 Response" overflow="wrap" %}

```javascript
{
    error: 'Unauthenticated call to createCustomer. Please re-authenticate and try again.'
}
```

{% endcode %}
{% endtab %}

{% tab title="404: Not Found user not found error" %}
{% code title="Example 404 Response" overflow="wrap" %}

```javascript
{
    error: 'No user found with provided address: 0x218C2BbaaBa0D66ddcD5De942Ed2980Bbfd1f004'
}
```

{% endcode %}
{% endtab %}

{% tab title="500: Internal Server Error internal server error" %}
{% code title="Example 500 Response" overflow="wrap" %}

```javascript
{
    error: 'An internal server error occurred. Please check the request body, ensure you are authenticated, and try again.'
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Get Setup Intent client secret to capture payment method

<mark style="color:blue;">`GET`</mark> `https://gateway-relay.herokuapp.com/api/stripe/getSetupIntent`

#### Headers

| Name                                            | Type      | Description                                                                                                                                                                                                                                                                         |
| ----------------------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | jwt token | received via authenticating with the [auth endpoints.](https://karan-khullar.gitbook.io/gateway/documentation/api-reference/auth) **To learn more about the authentication flow, click** [**here**](https://karan-khullar.gitbook.io/gateway/architecture/authentication-flow)**.** |

{% tabs %}
{% tab title="200: OK successful operation" %}
{% code title="Example 200 Response" overflow="wrap" %}

```javascript
{
    clientSecret: 'client...secret'
}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized authentication error" %}
{% code title="Example 401 Response" overflow="wrap" %}

```javascript
{
    error: 'Unauthenticated call to getSetupIntent. Please re-authenticate and try again.'
}
```

{% endcode %}
{% endtab %}

{% tab title="404: Not Found user not found error" %}
{% code title="Example 404 Response" overflow="wrap" %}

```javascript
{
    error: 'No user found with provided address: 0x218C2BbaaBa0D66ddcD5De942Ed2980Bbfd1f004'
}
```

{% endcode %}
{% endtab %}

{% tab title="404: Not Found stripe customer not found error" %}
{% code title="Example 404 Response" overflow="wrap" %}

```javascript
{
    error: 'No user found with the provided stripe_id: cus_MD1vEjQloWXPQy'
}
```

{% endcode %}
{% endtab %}

{% tab title="500: Internal Server Error internal stripe error" %}
{% code title="Example 500 Response" overflow="wrap" %}

```javascript
{
    error: 'here was an issue generating a setup intent for the following customer: cus_MD1vEjQloWXPQy'
}
```

{% endcode %}
{% endtab %}

{% tab title="500: Internal Server Error internal server error" %}
{% code title="Example 500 Response" overflow="wrap" %}

```javascript
{
    error: 'An internal server error occurred. Please check the request body, ensure you are authenticated, and try again.'
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Insert or update existing subscription

<mark style="color:green;">`POST`</mark> `https://gateway-relay.herokuapp.com/api/stripe/upsertSubscription`

#### Path Parameters

| Name                                            | Type      | Description                                                                                                                                                                                                                                                                         |
| ----------------------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | jwt token | received via authenticating with the [auth endpoints.](https://karan-khullar.gitbook.io/gateway/documentation/api-reference/auth) **To learn more about the authentication flow, click** [**here**](https://karan-khullar.gitbook.io/gateway/architecture/authentication-flow)**.** |

#### Request Body

| Name                                               | Type    | Description                                                                                                                                                                                                                         |
| -------------------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| subscriptionCost<mark style="color:red;">\*</mark> | integer | <p>parameter that describes the monthly subscription amount. should be the dollar value multiplied by 100. </p><p><em>example: a subscriptionCost of <strong>$25.50</strong> would be represented as <strong>2550</strong></em></p> |
| currency                                           | string  | optional parameter describing the currency of the subscription. the default is usd.                                                                                                                                                 |
| cancelAtEndOfBillingPeriod                         | boolean | optional parameter describing whether this subscription should be canceled after one billing period. the default is false.                                                                                                          |

{% tabs %}
{% tab title="200: OK successful operation" %}
{% code title="Example 200 Response" overflow="wrap" %}

```javascript
{
    subscriptionId: 'sub_1LVjtfBcTnTxBQNZpkuSZvqL',
    subscriptionFor: 'cus_MD1vEjQloWXPQy',
    subscriptionAmount: '$25.50'
}
```

{% endcode %}
{% endtab %}

{% tab title="404: Not Found user not found error" %}
{% code title="Example 404 Response" overflow="wrap" %}

```javascript
{
    error: 'No user found with provided address: 0x218C2BbaaBa0D66ddcD5De942Ed2980Bbfd1f004'
}
```

{% endcode %}
{% endtab %}

{% tab title="404: Not Found stripe customer not found error" %}
{% code title="Example 404 Response" overflow="wrap" %}

```javascript
{
    error: 'No user found with the provided stripe_id: cus_MD1vEjQloWXPQy'
}
```

{% endcode %}
{% endtab %}

{% tab title="500: Internal Server Error internal service error" %}
{% code title="Example 500 Response" overflow="wrap" %}

```javascript
{
    error: 'An internal server error occurred. Please check the request body, ensure you are authenticated, and try again.'
}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized authentication error" %}
{% code title="Example 401 Response" overflow="wrap" %}

```javascript
{
    error: 'Unauthenticated call to upsertSubscription. Please re-authenticate and try again.'
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Cancel existing subscription

<mark style="color:red;">`DELETE`</mark> `https://gateway-relay.herokuapp.com/api/stripe/cancelSubscription`

#### Headers

| Name                                            | Type      | Description                                                                                                                                                                                                                                                                         |
| ----------------------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | jwt token | received via authenticating with the [auth endpoints.](https://karan-khullar.gitbook.io/gateway/documentation/api-reference/auth) **To learn more about the authentication flow, click** [**here**](https://karan-khullar.gitbook.io/gateway/architecture/authentication-flow)**.** |

#### Request Body

| Name                                                | Type    | Description                                                                                                                |
| --------------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------- |
| cancelImmediately<mark style="color:red;">\*</mark> | boolean | parameter that describes whether or not to cancel the subscription immedietly, or at the end of the current billing cycle. |

{% tabs %}
{% tab title="200: OK successful operation" %}
{% code title="Example 200 Response" overflow="wrap" %}

```javascript
{
    success: true,
    customerIdCancelledFor: 'cus_MD1vEjQloWXPQy',
    cancelledInstantly: true
}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized authentication error" %}
{% code title="Example 401 Response" overflow="wrap" %}

```javascript
{
    error: 'Unauthenticated call to getSetupIntent. Please re-authenticate and try again.'
}
```

{% endcode %}
{% endtab %}

{% tab title="404: Not Found user not found error" %}
{% code title="Example 404 Response" overflow="wrap" %}

```javascript
{
    error: 'No user found with provided address: 0x218C2BbaaBa0D66ddcD5De942Ed2980Bbfd1f004'
}
```

{% endcode %}
{% endtab %}

{% tab title="404: Not Found stripe customer not found error" %}
{% code title="Example 404 Response" overflow="wrap" %}

```javascript
{
    error: 'No user found with the provided stripe_id: cus_MD1vEjQloWXPQy'
}
```

{% endcode %}
{% endtab %}

{% tab title="500: Internal Server Error internal server error" %}
{% code title="Example 500 Response" overflow="wrap" %}

```javascript
{
    error: 'An internal server error occurred. Please check the request body, ensure you are authenticated, and try again.'
}
```

{% endcode %}
{% endtab %}
{% endtabs %}
