# Stripe

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2F2EYaMRH6v634OSLdxq3P%2Fimage.png?alt=media&#x26;token=56b0f605-8b89-4ed8-895e-6dc516c26aad" alt="" width="188"><figcaption><p>Stripe Service</p></figcaption></figure></div>

The Stripe service allows you to accept payments in your app using the [Stripe payment services](https://stripe.com/).

***

## API Keys

[Stripe API keys](https://stripe.com/docs/keys) come in pairs:

* Publishable Key: This is meant for use within the pages of your app.
* Secret Key: Used in your app's Zingy Cloud backend.

Now, there are two distinct sets of these keys:

* [Test mode](https://stripe.com/docs/test-mode): Used to test your app's integration with Stripe. The [Page Editor's preview feature](https://docs.zingy.ai/app-editor/page-editor/page-preview) will use the test mode when using this service.&#x20;
* Live mode: Used in the live version of the app.&#x20;

{% hint style="warning" %}
NOTE: Use the [test credit card numbers](https://stripe.com/docs/testing#cards) to accept payments in test mode.
{% endhint %}

***

## Profile Settings

{% hint style="success" %}
NOTE: All profile settings are encrypted and stored in Zingy's cloud infrastructure.
{% endhint %}

### Test Mode Publishable Key

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FVrv9GJ2bMo8zQN1cQcWO%2Fimage.png?alt=media&#x26;token=a8e982ff-9ac6-4e38-a612-4ea6af72c07f" alt="" width="375"><figcaption></figcaption></figure></div>

Enter the test mode [publishable key](#api-keys) here.

### Test Mode Secret Key

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FlfHYsuOIiHLGfQnPUJoH%2Fimage.png?alt=media&#x26;token=d2cc6473-2ad1-4549-bbfc-24674acfbfcd" alt="" width="375"><figcaption></figcaption></figure></div>

Enter the test mode [secret key](#api-keys) here.

### Live Mode Publishable Key

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FjBuVTeLC6lTKWOqwSd2m%2Fimage.png?alt=media&#x26;token=95e5a2eb-87e1-40ad-ab06-121854376f2d" alt="" width="375"><figcaption></figcaption></figure></div>

Enter the live mode [publishable key](#api-keys) here.

### Live Mode Secret Key

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FjVu48wtmTzLFcwCqFRFU%2Fimage.png?alt=media&#x26;token=257698e5-572a-4625-9fea-dad8a803a7df" alt="" width="375"><figcaption></figcaption></figure></div>

Enter the live mode [secret key](#api-keys) here.

### Currency Code

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FKg8lG9sjTwCpC96KxNBb%2Fimage.png?alt=media&#x26;token=77a9b07f-3c62-460c-b96d-beaa8a4db37a" alt="" width="375"><figcaption></figcaption></figure></div>

Enter the [3 letter ISO currency code](https://www.iso.org/iso-4217-currency-codes.html) associated with your account. Please note that this must be a [Stripe supported currency](https://stripe.com/docs/currencies).

If not provided the default value of *usd* will be used.

***

## Widgets

The [Stripe Payment](https://docs.zingy.ai/app-editor/page-editor/built-in-elements/stripe-payment) widget element provides a quick and easy way to add payment functionality to any page or form. This element makes use of the Stripe service.

***

## Operations/Commands

The [Execute Connection Command](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/execute-connection-command) block is available in both [Page Flow](https://docs.zingy.ai/app-editor/page-flow) and [Cloud Flow](https://docs.zingy.ai/app-editor/cloud-flow). Using this block you can add logic to trigger the operations/commands supported by the Stripe service.

### Create Payment Intent

In Stripe, a [Payment Intent](https://stripe.com/docs/payments/payment-intents) represents an attempt to collect payment from a customer. Normally the process of creating a payment intent is automatically done if you use the [Stripe Payment](https://docs.zingy.ai/app-editor/page-editor/built-in-elements/stripe-payment) widget element with a specified [configured amount](https://docs.zingy.ai/page-editor/built-in-elements/stripe-payment#amount).

For custom implementations using [Page Flow](https://docs.zingy.ai/app-editor/page-flow) and [Cloud Flow](https://docs.zingy.ai/app-editor/cloud-flow), you can use the Create Payment Intent command to create the payment intent.

#### Input Data

When invoking this operation, an object with the following properties is required:

<table><thead><tr><th width="149">Property</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td>amount</td><td><a href="../../page-flow/references/value-types">numeric</a></td><td>Specify the amount to charge.</td></tr><tr><td>customProps</td><td><a href="../../page-flow/references/value-types">object</a></td><td>Optional. For advanced users, this specifies an object with properties based on parameters used by <a href="https://stripe.com/docs/api/payment_intents/create">Stripe's API</a>.</td></tr></tbody></table>

#### Output

Upon success, the operation provides an object with the following properties:

<table><thead><tr><th width="173">Property</th><th width="76">Type</th><th>Description</th></tr></thead><tbody><tr><td>client_secret</td><td><a href="../../page-flow/references/value-types">text</a></td><td>Is a <a href="https://stripe.com/docs/api/payment_intents/object#payment_intent_object-client_secret">unique key provided by Stripe</a> for each Payment Intent you create.</td></tr><tr><td>publishable_key</td><td><a href="../../page-flow/references/value-types">text</a></td><td>The publishable <a href="#api-keys">API Key</a> to use.</td></tr></tbody></table>

### Confirm Payment Intent

Once a payment intent is created, the Stripe's payment payment collection form can be presented to the user.  The [Stripe Payment](https://docs.zingy.ai/app-editor/page-editor/built-in-elements/stripe-payment) widget element automatically does this.

For any custom implementation, where you present Stripe's payment payment collection form yourself, once the user finalizes the payment, Zingy's cloud backend can retrieve the confirmation details and record the transaction in the Connection Data for the service.

The Confirm Payment Intent command informs Zingy's cloud backend that the payment procedure has concluded, prompting the backend to register the payment details.

#### Input Data

When invoking this operation, an object with the following properties is required:

<table><thead><tr><th width="272">Property</th><th width="85">Type</th><th>Description</th></tr></thead><tbody><tr><td>payment_intent</td><td><a href="../../page-flow/references/value-types">text</a></td><td>The payment identifier provided by Stripe's client side API.</td></tr><tr><td>payment_intent_client_secret</td><td><a href="../../page-flow/references/value-types">text</a></td><td>The client_secret provided by the <a href="#create-payment-intent">Create Payment Intent</a> command.</td></tr><tr><td>sgInstName</td><td><a href="../../page-flow/references/value-types">text</a></td><td>Optional. Name of the <a href="sendgrid">Sendgrid service</a> connection to use for automatically sending the user a payment receipt email.</td></tr><tr><td>notfnEmail</td><td><a href="../../page-flow/references/value-types">text</a></td><td>Optional. The email address where an automatic payment notification email is sent. Valid only if <em>sgInstName</em> is provided and sendNotfn is set to <em>true</em>.</td></tr><tr><td>emailCust</td><td><a href="../../page-flow/references/value-types">text</a></td><td>Optional. If the value is <em>true</em>, an automatic email receipt will be sent to the customer based on information retrieved from Stripe's payment confirmation. Valid only if <em>sgInstName</em> is provided.</td></tr><tr><td>sendNotfn</td><td><a href="../../page-flow/references/value-types">text</a></td><td>Optional. If the value is <em>true</em>, and a valid notfnEmail is provided, a notification will be sent. </td></tr></tbody></table>

#### Output

The Confirm Payment Intent command does not provide any output beyond the Success/Fail status.

***

## Advanced Functionality

In your app's Cloud Flow Web Hooks and Background Tasks, the [Custom Code](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/custom-code) block can be used to access and implement advanced functionality related to the Stripe payment service.

To access the Stripe client initialized with credentials saved on this Stripe service connection, see the following example:

```javascript
// To use a stripe client initialized with credentials provided 
// in a Stripe connection
const stripe = zingyConn.stripe(connectionName);
```

You may also initialize a seperate Stripe client, by specifying account credentials directly:

```javascript
// To create a new stripe client specifying account credentials
const stripe = require('stripe')(secret);
```

After the `stripe` object is initialized, you can use it to call into the Stripe library. Refer to [Stripe library documentation](https://www.npmjs.com/package/stripe) for more information.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zingy.ai/app-editor/connections/services/stripe.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
