Generate unique card token

My system has automatic top up system, so we need to save our customer and token to our Omise account, but when our system try to save the customer via Omise PHP package, it always produces errors which says “Token was already used” although that token (generated by Omise.js) that is used is new, my question is how do i generate unique token ?, or how do i tackle this issue ?

Thank you

Hi!

A token can be used only once. So, please ensure that you never used it before e.g. create a charge or attached to another customer.

Hi, i created that token using Omise.js, so i need to test them manually to ensure that token that is generated is unique ?

Ok, i found the issue, thank you

Hi!

No. The given token is always unique. I would like to give you a simple example.

  1. We have to create a token via Token API, in this case, we are using Omise.js to help us creating a token.
  2. In this step, we get a token right?.. then we will send the token to server to do something.
  3. If this step we want to create a charge, just do it… and then token is used. We can’t use the token anymore.
  4. We use the token to create a customer. Now, we will get "Token was already used” message.

Ok then, if we need to create a customer and a charge… just change the flow in step 3 and 4.
3. Create a customer using a given token, now we will get a customer.
4. Create a charge using a given customer id. That’s it.

You can find more information and example in https://www.omise.co/charges-api.
Cheers

Ok, thanks for your information, my mistake was using same token for charging and creating user, i though this uniqueness only apply for creating user.

1 Like