{"action":"created","issue":{"url":"https://api.github.com/repos/omise/omise-node/issues/50","repository_url":"https://api.github.com/repos/omise/omise-node","labels_url":"https://api.github.com/repos/omise/omise-node/issues/50/labels{/name}","comments_url":"https://api.github.com/repos/omise/omise-node/issues/50/comments","events_url":"https://api.github.com/repos/omise/omise-node/issues/50/events","html_url":"https://github.com/omise/omise-node/issues/50","id":186091483,"number":50,"title":"Error: card was not found, hard to reproduce","user":{"login":"PanJ","id":1797879,"avatar_url":"https://avatars.githubusercontent.com/u/1797879?v=3","gravatar_id":"","url":"https://api.github.com/users/PanJ","html_url":"https://github.com/PanJ","followers_url":"https://api.github.com/users/PanJ/followers","following_url":"https://api.github.com/users/PanJ/following{/other_user}","gists_url":"https://api.github.com/users/PanJ/gists{/gist_id}","starred_url":"https://api.github.com/users/PanJ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PanJ/subscriptions","organizations_url":"https://api.github.com/users/PanJ/orgs","repos_url":"https://api.github.com/users/PanJ/repos","events_url":"https://api.github.com/users/PanJ/events{/privacy}","received_events_url":"https://api.github.com/users/PanJ/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-10-29T17:51:02Z","updated_at":"2016-10-29T20:53:41Z","closed_at":null,"body":"Hi again,\r\n\r\nI am having weird bug right now, which is hard to reproduce. The detail as follows\r\n- The error message is `card tokn_test_55tsnhljnyn2d8ye0br was not found` when trying to charge a card\r\n- The bug occurs unpredictably from time to time\r\n- If the issue occurs, it will persist until the running app is restarted\r\n- After restart, it will work normally as expected\r\n\r\nHappened to me 2 times this week. I am running the library on nodejs v5 the code looks like this\r\n\r\n```javascript\r\nconst omise = require('omise')({\r\n  secretKey: 'xxx',\r\n  omiseVersion: '2015-11-17'\r\n});\r\n...\r\napp.get('charge', (req, res) => {\r\n    Promise.resolve({\r\n      amount: req.query.amount,\r\n      card: req.query.token,\r\n      currency: 'THB',\r\n    })\r\n    .then(omise.charges.create)\r\n    .then((response) => {\r\n      // check for error\r\n    })\r\n    .then((data) => res.send(data))\r\n    .catch((err) => res.error(err));\r\n})\r\n```\r\nAnd 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.\r\n\r\nPlease let me know if you have any idea about this issue.\r\n\r\nThanks!\r\nPanJ"},"comment":{"url":"https://api.github.com/repos/omise/omise-node/issues/comments/257115504","html_url":"https://github.com/omise/omise-node/issues/50#issuecomment-257115504","issue_url":"https://api.github.com/repos/omise/omise-node/issues/50","id":257115504,"user":{"login":"PanJ","id":1797879,"avatar_url":"https://avatars.githubusercontent.com/u/1797879?v=3","gravatar_id":"","url":"https://api.github.com/users/PanJ","html_url":"https://github.com/PanJ","followers_url":"https://api.github.com/users/PanJ/followers","following_url":"https://api.github.com/users/PanJ/following{/other_user}","gists_url":"https://api.github.com/users/PanJ/gists{/gist_id}","starred_url":"https://api.github.com/users/PanJ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PanJ/subscriptions","organizations_url":"https://api.github.com/users/PanJ/orgs","repos_url":"https://api.github.com/users/PanJ/repos","events_url":"https://api.github.com/users/PanJ/events{/privacy}","received_events_url":"https://api.github.com/users/PanJ/received_events","type":"User","site_admin":false},"created_at":"2016-10-29T20:53:41Z","updated_at":"2016-10-29T20:53:41Z","body":"That helps a lot in finding the root cause. I'll investigate the code on my\nside and give an update soon. Thank you!\n\nOn Sunday, 30 October 2016, Robin Clart <notifications@github.com> wrote:\n\n> For the omise being mutated, I'm not an expert in node so I'll let the\n> dev in charge of this lib have a look at it.\n>\n> However I went and looked up this specific token, and in this case,\n> there's a customer passed in the request (see below) which is why the token\n> can't be found. Whenever you're passing both a customer and a card, the\n> card will be found inside of the cards already attached to a customer using\n> their ID (those IDs starts with card_ and not tokn_).\n>\n> In your code, do you have some global customer variable always being\n> merged into the params object or something similar?\n>\n> {\n>   \"customer\": \"cust_test_55mz3j26fvl9nlnapwv\",\n>   \"card\": \"tokn_test_55tsnhljnyn2d8ye0br\",\n>   \"currency\": \"THB\",\n>   \"amount\": 300000,\n> }\n>\n> —\n> You are receiving this because you authored the thread.\n> Reply to this email directly, view it on GitHub\n> <https://github.com/omise/omise-node/issues/50#issuecomment-257107159>,\n> or mute the thread\n> <https://github.com/notifications/unsubscribe-auth/ABtu9501Y-1Rbj-9O78fBVQzETpKvQ3Cks5q442qgaJpZM4KkLIR>\n> .\n>\n\n\n-- \n*PanJ,*\nPanjamapong Sermsawatsri\n*Tel.* (+66)869761168\n"}}
{"actor":{"display_login":"PanJ"}}