paylike/sdk

Popup callback is not called when there is an unsuccessful payment attempt

ericallam opened this issue · 6 comments

I'm currently integrating the Web SDK and am attempting to simulate an unsuccessful payment attempt using a test account. When I do simulate this using the card # 4200 0000 0000 0000 I can see that the POST https://gateway.paylike.io/transactions XHR request results in a response code of 400 and response body is the following JSON:

{
	"code": 3,
	"message": "Invalid card number",
	"client": true,
	"merchant": false,
	"response": {
		"transaction": {
			"id": "<transaction id>"
		}
	}
}

I'd expect that the callback supplied to Paylike.popup would be called at this point with the first parameter having information about the parsed response body of the above XHR request. Unfortunately, the callback is not called at all.

Keeping track of these failed attempts is useful for anti-money laundering and fraud detection.

Hi @ericallam,

Thanks for reaching out.

It's correct that the callback is not called for each "attempt". The callback is only called when the popup is closed either manually or due to a successful transaction.
Calling the callback on each attempt would violate best practices for callback-taking APIs.

What we are instead looking at currently is adding "events" to the popup instance so that you can catch these intermediate things. I think that would solve your request as well.

You can currently work around this by instead pulling the failed transactions using our API:

curl -u :$APP_KEY "https://api.paylike.io/merchants/<merchant-id>/transactions?limit=10&filter\[successful\]=n"

If you are looking at AML and fraud detection, that is probably the preferred solution as it will be "tamper proof" when running on your server.

@tjconcept thanks for the reply and that makes sense about the callback API not being right for getting notified of the events. Thank you for the pointer to the failed transaction API, I will be using that instead of relying on the client like you said. Cheers!

@tjconcept, one more query for you. Is there any way to fetch successful and failed transactions in one request to the API? Or do they need to be done separately?

Yep:

curl -u :$APP_KEY "https://api.paylike.io/merchants/<merchant-id>/transactions?limit=10&filter\[successful\]=both"

Hi @Raynellc,

I am not sure I understand your question, could you try rephrasing?