Error: card was not found, hard to reproduce
Closed this issue · 5 comments
Hi again,
I am having weird bug right now, which is hard to reproduce. The detail as follows
- The error message is
card tokn_test_55tsnhljnyn2d8ye0br was not found
when trying to charge a card - The bug occurs unpredictably from time to time
- If the issue occurs, it will persist until the running app is restarted
- After restart, it will work normally as expected
Happened to me 2 times this week. I am running the library on nodejs v5 the code looks like this
const omise = require('omise')({
secretKey: 'xxx',
omiseVersion: '2015-11-17'
});
...
app.get('charge', (req, res) => {
Promise.resolve({
amount: req.query.amount,
card: req.query.token,
currency: 'THB',
})
.then(omise.charges.create)
.then((response) => {
// check for error
})
.then((data) => res.send(data))
.catch((err) => res.error(err));
})
And I am suspecting that omise
object is persisted for too long and somehow is mutated, then the bug occurs. I will try to move omise
inside the (req, res) => { ... }
and see if the bug still occur.
Please let me know if you have any idea about this issue.
Thanks!
PanJ
For the omise
object being mutated, I'm not an expert in node so I'll let the dev in charge of this lib have a look at it.
However I went and looked up this specific token, and in this case, there's a customer passed in the request (see below) which is why the token can't be found. Whenever you're passing both a customer and a card, the card will be found inside of the cards already attached to a customer using their ID (those IDs starts with card_
and not tokn_
).
In your code, do you have some global customer variable always being merged into the params object or something similar?
{
"customer": "cust_test_55mz3j26fvl9nlnapwv",
"card": "tokn_test_55tsnhljnyn2d8ye0br",
"currency": "THB",
"amount": 300000,
}
That helps a lot in finding the root cause. I'll investigate the code on my
side and give an update soon. Thank you!
On Sunday, 30 October 2016, Robin Clart notifications@github.com wrote:
For the omise being mutated, I'm not an expert in node so I'll let the
dev in charge of this lib have a look at it.However I went and looked up this specific token, and in this case,
there's a customer passed in the request (see below) which is why the token
can't be found. Whenever you're passing both a customer and a card, the
card will be found inside of the cards already attached to a customer using
their ID (those IDs starts with card_ and not tokn_).In your code, do you have some global customer variable always being
merged into the params object or something similar?{
"customer": "cust_test_55mz3j26fvl9nlnapwv",
"card": "tokn_test_55tsnhljnyn2d8ye0br",
"currency": "THB",
"amount": 300000,
}—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#50 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABtu9501Y-1Rbj-9O78fBVQzETpKvQ3Cks5q442qgaJpZM4KkLIR
.
PanJ,
Panjamapong Sermsawatsri
Tel. (+66)869761168
I have checked the code and there is no way the customer
attribute can be leaked into the function, which means that it is likely to be the bug in the library itself.
function _makeOptions(options, path, data) {
return _.merge(options, path, {body: data});
}
I think maybe cause this function merge use same options object every request.
It should be fixed: https://github.com/omise/omise-node/releases/tag/v0.5.3