Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate Transaction Reference "KES" not issue #74, but similar #95

Closed
kevinrobert3 opened this issue Mar 8, 2024 · 6 comments
Closed

Comments

@kevinrobert3
Copy link

kevinrobert3 commented Mar 8, 2024

We are using KES and are guessing the plugin takes the cart amount as the actual cart amount, e.g KES 3650 is translated as KES 3650 to Paystack by plugin.

The issue comes in the popup, when one passes 3650 * 100 you get a 'duplicate transaction reference'.
Passing it as original amount "3650" makes the payment KES 36.5 which is wrong but payment succeeds.

Also I don't know whether to raise a new issue for this too. But when the erroneous "KES 36.5" transaction completes the plugin fails to complete the cart with error

error:   current transaction is aborted, commands ignored until end of transaction block
QueryFailedError: current transaction is aborted, commands ignored until end of transaction block

and

node_modules/typeorm/query-builder/SelectQueryBuilder.js:750:25) {
  query: 'SELECT "Cart"."id" AS "Cart_id", "Cart"."created_at" AS "Cart_created_at", "Cart"."updated_at" AS "Cart_updated_at", "Cart"."deleted_at" AS "Cart_deleted_at", "Cart"."email" AS "Cart_email", "Cart"."billing_address_id" AS "Cart_billing_address_id", "Cart"."shipping_address_id" AS "Cart_shipping_address_id", "Cart"."region_id" AS "Cart_region_id", "Cart"."customer_id" AS "Cart_customer_id", "Cart"."payment_id" AS "Cart_payment_id", "Cart"."type" AS "Cart_type", "Cart"."completed_at" AS "Cart_completed_at", "Cart"."payment_authorized_at" AS "Cart_payment_authorized_at", "Cart"."idempotency_key" AS "Cart_idempotency_key", "Cart"."context" AS "Cart_context", "Cart"."metadata" AS "Cart_metadata", "Cart"."sales_channel_id" AS "Cart_sales_channel_id", "Cart"."store_id" AS "Cart_store_id" FROM "public"."cart" "Cart" WHERE ( (("Cart"."id" = $1)) ) AND ( "Cart"."deleted_at" IS NULL ) LIMIT 1',
  parameters: [ 'cart_01HRET3DYVETJMSF0P09NSD' ],
  driverError: error: current transaction is aborted, commands ignored until end of transaction block
     ) {
    length: 145,
    severity: 'ERROR',
    code: '25P02',
    detail: undefined,
    hint: undefined,
    position: undefined,
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'postgres.c',
    line: '1470',
    routine: 'exec_parse_message'
  },
  length: 145,
  severity: 'ERROR',
  code: '25P02',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'postgres.c',
  line: '1470',
  routine: 'exec_parse_message'
}

I am guessing the plugin is somehow looking to check if amounts are same. Which would always be false since cart has KES 3650 (in db/medusa) and paid amount is KES 36.5 (paystack)

@a11rew
Copy link
Owner

a11rew commented Mar 8, 2024

Yes you are right on the plugin taking the cart amount and sending that to Paystack. In Medusa and the plugin by extension, prices are represented in the lowest denomination of the currency. To charge KES 3650 in your case, you need to provide the prices in the admin as 3650 * 100.

The default Medusa starter localizes the amounts and so it should show up as KES 3650 on your frontend pages with 365000 given to the plugin and subsequently sent to Paystack.

@a11rew
Copy link
Owner

a11rew commented Mar 8, 2024

Please do create a separate issue for the transaction failing issue. The error logs you added are indicative of an issue after the original failure which probably happened in the plugin. You could enable debug mode in the plugin to see extra logs which could guide you to what is failing. Add debug: true to the plugin's config to enable debug mode

@kevinrobert3
Copy link
Author

kevinrobert3 commented Mar 8, 2024

Isn't that a bit off that I need to add my prices in backend as KES 365000, that means changing so much across the board, e.g. for other currencies, showing it back in storefront etc. When we could get an option to change the value before the plugin consumes it. Adding the prices as n * 100 in backend is changing a lot of inner workings, even for reporting, only to accommodate Paystack. Also check the other issue similar to this, that would mean the person has to change the prices in their backend in the live environment to accommodate paystack

@kevinrobert3
Copy link
Author

kevinrobert3 commented Mar 8, 2024

It would also mean that someone who has used a different payment processor and chooses Paystack later with the plugin would have to change all their product prices to n * 100 to use the plugin.

I propose push a breaking change in plugin doing the n * 100 internally. Everybody is sorted that way in the most least effort way

@a11rew
Copy link
Owner

a11rew commented Mar 8, 2024

I am confused. To clarify, are you using the default Medusa admin dashboard?

If you are, this is what adding KES prices should look like:
image

When being saved to the backend, the admin dashboard automatically localizes the prices to the lowest denomination before sending to the backend, i.e. the n*100 conversion you want done.
image

Prices will be stored in the database with this value and all the other parts of Medusa (fulfillment, storefront, this plugin etc) expect the prices in the lowest denomination. Paystack also expects amounts in the lowest denomination (i.e. to pay KES 3650, the amount value sent to Paystack needs to be 365000). You can confirm this from the Checkout demo.

This is the default behaviour and I suggested performing the n*100 conversion yourself because I imagined you were on a custom admin. You shouldn't need to do that otherwise.

You'd have to provide more information on your setup and changes you have added that may affect how amounts are set in your store for us to be able to help.

@kevinrobert3
Copy link
Author

Oh wow. I actually really noticed the prices in the other issue' screenshots. I had not noticed this price amounts. Yes I am on a custom admin. This is all fine then. The most weird thing to do and see, however, but I'll change the prices on my end.
I'll close this one and open the other issue

@a11rew a11rew closed this as completed Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants