# Saving down details of a transaction

In order to save down details of a transaction, I suggest creating the following fields in a "transaction" data type in your database:

* checkout session id (text)
* currency (text)
* customer (text)
* payment status (text)
* total amount (number)

There are also several other fields that I would consider optional (depending on what data you want to retain):

* payment intent id (text)
* payment method (text)
* last 4 digits (text)

You can see an example of such a database setup in [this demo app](https://bubble.io/page?type=page\&name=index\&id=shopping-cart-demo-67649\&tab=tabs-3\&subtab=Data+Types\&type_id=transaction).

<div align="left"><figure><img src="https://2484116937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5veFxRNePefac6Z9yAnL%2Fuploads%2FW8hy46IqF6saC57kpzzN%2FScreenshot%202023-09-02%20at%2011.05.40.png?alt=media&#x26;token=ce81f577-bc04-4bbc-9c6a-4fc25dd73734" alt="" width="563"><figcaption></figcaption></figure></div>

You can use the "checkout session id" and the "Retrieve Checkout Session Details" API call to save down details of a transaction.

* You'll first need to identify the transaction being processed in the "Success URL" and "Cancel URL" fields when [creating the Stripe Checkout Session](creating-checkout-sessions)
* You can do this by referencing the unique ID of the transaction as a Page URL Parameter

<div align="left"><figure><img src="https://2484116937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5veFxRNePefac6Z9yAnL%2Fuploads%2FBgz70h53ReYgEmxEk6qi%2FScreenshot%202023-09-02%20at%2011.09.01.png?alt=media&#x26;token=dc92ed50-4ff7-4fe9-9707-6a4b7826428c" alt="" width="322"><figcaption></figcaption></figure></div>

* In the above example, the unique ID of the transaction is being referenced in the "?transaction=Result of step 1 (Create a new Tran...)'s unique id
* This means that when you are on the Success URL or Cancel URL page, you can use the unique id of the transaction in the page URL to save down data

<div align="left"><figure><img src="https://2484116937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5veFxRNePefac6Z9yAnL%2Fuploads%2Fb26lMlOIu2HjVAQqxXhd%2FScreenshot%202023-09-02%20at%2011.12.36.png?alt=media&#x26;token=3199be5c-5c65-4f71-8cfe-db82cc3a2d6d" alt="" width="563"><figcaption></figcaption></figure></div>

* You can run a workflow on "page load" that only runs when the "transaction" parameter int the page URL is **not** empty

<div align="left"><figure><img src="https://2484116937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5veFxRNePefac6Z9yAnL%2Fuploads%2Fo5TSOEVrA13rMwqDtODo%2FScreenshot%202023-09-02%20at%2011.14.23.png?alt=media&#x26;token=c5e0d4a1-d74b-4d10-91ee-0f859e895b83" alt="" width="375"><figcaption></figcaption></figure></div>

* You can then use the "Stripe - Retrieve Checkout Session Details" call to update the "payment status" and "currency"

<div align="left"><figure><img src="https://2484116937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5veFxRNePefac6Z9yAnL%2Fuploads%2FccmDVpPPKsuAL2oDLxSz%2FScreenshot%202023-09-02%20at%2011.16.42.png?alt=media&#x26;token=bbba88c1-a35c-4d79-b3d1-e45f6b161850" alt="" width="563"><figcaption></figcaption></figure></div>

You can see an example of how to do this in the below tutorial video (from 22:36 on)

{% embed url="https://www.youtube.com/watch?v=aRsvpQZToOA" %}

**Saving down data for optional fields**

As mentioned above, you may also wish to save down data for fields such as:

* payment intent id
  * You can use the "Stripe - Get Checkout Session Details" call to save down the payment intent id
* payment intent method
  * You can use the "Get Payment Details" call (will require you input the payment intent id) to get the payment intent method
* last 4 digits
  * You can use the "Stripe - Retrieve a Payment Method" call (will require you input the payment intent method) to get the last 4 digits of the card used in the Checkout Session

