Refresh Information Stripe

I'm currently working on implementing Stripe, and utilizing metadata in the process.

Everything works smoothly until I come across a scenario where I need to update a value in the metadata to determine if a specific uuid has been used before.

    payment_intent_data: {
      metadata: {
        uuid: usedUuid,
        isUsed: "false",
      },

Here's an example of the function I'm using to verify the validity of the UUID, and I'm unsure about how to update the metadata for the invalidate function:

async function isValidUuid(uuid: string): Promise<boolean> {
  // TODO: check if uuid has been used before and its valid
  var isValid = uuid4.valid(uuid);
  const charges = await stripe.charges.search({
    query: `metadata[\'uuid\']:${uuid} AND metadata[\'isUsed\']:\'false\'`,
  });

  return isValid && charges.data.length > 0;
}

Can someone provide guidance on updating the isUsed field?

Thanks in advance

Answer №1

To modify the metadata associated with a particular charge, simply make a call to the update charge function[1]. You only need to provide the keys of the metadata that you wish to change, meaning that updating one key like isUsed will not impact your uuid value.

const charge = await stripe.charges.update(
  'ch_123',
  {metadata: {isUsed: 'true'}}
);

It's important to note that PaymentIntent and Charge objects have separate copies of their metadata. When a Charge is initially created, the PaymentIntent's metadata is copied over, but there is no automatic synchronization afterwards. If you want to update the metadata on both entities, you'll have to perform two distinct API calls[1][2]. However, if the updated metadata only needs to apply to the charge, then this step can be skipped.

const charge = await stripe.charges.update(
  'ch_123',
  {metadata: {isUsed: 'true'}}
);

const paymentIntent = await stripe.paymentIntents.update(
  'pi_456',
  {metadata: {isUsed: 'true'}}
);

[1] https://stripe.com/docs/api/charges/update#update_charge-metadata [2] https://stripe.com/docs/api/payment_intents/update?lang=node#update_payment_intent-metadata

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to merge two interfaces and convert all of their fields to optional properties?

I have two unalterable interfaces: interface Person { name: string; age: number; } interface User { username: string; password: string; } I aim to merge them into a single interface called Player // please, adjust this code accordingly interfac ...

Is there a way to enable Tail Recursion Optimization in TypeScript?

const isPositive = (n: number) => n > 0; function fitsIn(dividend: number, divisor: number, count: number, accum: number): number { if (accum + divisor > dividend) { return count; } return ...

Creating a dynamic columns property for Mat-Grid-List

Is it possible to create a Mat-Grid-List where the number of columns can be dynamically changed based on the width of the container? Here is an example: <mat-grid-list [cols]="getAttachmentColumns()" rowHeight="100px" style="width: 100%;"> <mat ...

An issue has occurred: the function cannot be applied to the intermediate value that is currently being processed

I am currently working on an Angular 5 CRUD application, utilizing Google Firebase services. I have been following a helpful video tutorial on YouTube (link here), but I encountered this error ngOnInit() { var x = this.employeeService.getData(); x.sna ...

Creating a standard arrow function in React using TypeScript: A Step-by-Step Guide

I am currently working on developing a versatile wrapper component for Apollo GraphQL results. The main objective of this wrapper is to wait for the successful completion of the query and then render a component that has been passed as a prop. The componen ...

Loop through JSON results in Ionic using Angular

I am struggling to retrieve data from a JSON file in Object format using Typescript. When I try to fetch the data from the API, it doesn't display as expected. Typescript this.http.get('http://example.com/api') .subscribe((data) => { ...

Leveraging getStaticProps in Next.js

I am currently embarking on my inaugural Nextjs project, focused on developing a basic blog utilizing the JSON placeholder API. Strangely, I am encountering an issue where the prop "posts" is being perceived as undefined. Can anyone provide assistance with ...

Navigating to different HTML pages by utilizing <a> elements in Angular 2

As a newcomer to Angular 2, I've decided to build my personal website using this framework. The main page of my website contains bio information, while the other page will feature blog content. Both pages will have a shared header and footer, but diff ...

app-root component is not populating properly

As a newcomer to Angular 2, I have embarked on a small project with the following files: app.module.ts import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { MaterialModule } fro ...

Connecting Ionic 3 with Android native code: A step-by-step guide

I just finished going through the tutorial on helpstack.io and was able to successfully set up the HelpStackExample with android native based on the instructions provided in the GitHub repository. The only issue is that my company project uses Ionic 3. H ...

When running `npm test`, Mocha TS tests encounter failure, but the issue does not arise when executing them

When running tests in my Typescript nodejs project, I use the following command: mocha --compilers ts:ts-node/register,tsx:ts-node/register The tests run successfully with this command. However, when I try to run them using npm test, I encounter the foll ...

Formatting numbers in Angular 2 to include a space every three zeros in a money amount

Let's say I have the number 30000 and I want to format it as 30 000. What method should I use to achieve this? Here are more examples: 300000 -> 300 000, 3000000 -> 3 000 000. Just to clarify, this is not about using dots or commas, but rather reco ...

When multiple input fields with an iterative design are using the same onChange() function, the specific event.target.values for each input

I'm in the process of developing a dynamic select button that adjusts based on the information entered into the iterative input fields I've set up. These input fields all utilize the same onChange() function. for (let i = 0; i < selectCount; i ...

Encountered an issue with valid types while executing the following build

Encountering an error when attempting to run the next build process. https://i.stack.imgur.com/qM3Nm.png Tried various solutions including updating to ES6, switching the module to commonJs, downgrading webpack to version 4 with no success. The only worka ...

Utilizing Typescript to Transfer Data from Child to Parent in React

Attempting to pass data from a Child Component to a Parent component using Typescript can be challenging. While there are numerous resources available, not all of them delve into the TypeScript aspect. One question that arises is how the ProductType event ...

When using a typescript subscription to collect data from an API, the information is stored in an array. However, only one piece of data can be

I have implemented a method to fetch data from an API using Angular: ngAfterViewInit() { this.exampleDatabase = new ExampleHttpDatabase(this._httpClient); var href = '/schuhe-store/status'; if (environment.production === false) { href ...

Discovering the versatility of Typescript objects

I want to define a type that follows this rule: If the property container is present, then expect the property a. If the property item is present, then expect the property b. Both container and item cannot exist at the same time. The code I would expect ...

Error: The next.config.js file contains invalid options - The root value includes an unexpected property

I recently updated my next version from 10 to 12, and when I run the local development server, I encounter the following error in the terminal. As a result, the code fails to compile. How can I fix this issue? Invalid next.config.js options have been iden ...

Retrieving the final element from a TypeScript JSON array

I am trying to retrieve the value of the "id" property from the last element in an array of JSON objects. While I can easily find each element by id, I specifically need to extract the value of the last "id" in the array of JSON objects. In the example p ...

What is the best way to transmit a JSON object to a .NET server utilizing SignalR?

I am currently in the process of developing an Angular application that requires sending data from Angular forms to an external server using a .NET Core server and SignalR. While I have successfully established a connection between the Angular client and c ...