Drop-in requestPaymentMethod throws postMessage error.
See original GitHub issueGeneral information
- SDK/Library version: web/dropin/1.10.0
- Environment: Sandbox
- Browser and OS: Chrome 66.0.3359.139 (64-bit) on MacOS 10.12.3
Issue description
I reproduce demo where there is existing bug. When I provide new card data, and execute ‘requestPaymentMethod’ it’s stuck on ‘pending’ state and produce error in console log:
hosted-fields-frame.min.html:1 Uncaught (in promise) DOMException: Failed to execute 'postMessage' on 'Window': Invalid target origin 'null' in a call to 'postMessage'. at e.reply.e.reply (https://assets.braintreegateway.com/web/3.31.0/html/hosted-fields-frame.min.html:1:12317) at https://assets.braintreegateway.com/web/3.31.0/html/hosted-fields-frame.min.html:1:65690
Code:
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, target-densityDpi=device-dpi" />
<title>Braintree payment</title>
<script src="https://js.braintreegateway.com/web/dropin/1.10.0/js/dropin.min.js"></script>
</head>
<body>
<div id="dropin-container"></div>
<script>
let createBraintree = () => {
window.dropinHandler = braintree.dropin.create({
authorization: 'sandbox_**********************,
container: '#dropin-container'
}, function (createErr, instance) {
window.addEventListener('requestPayment', function () {
instance.requestPaymentMethod(function (requestPaymentMethodErr, payload) {
alert('Im in!');
});
});
});
};
createBraintree();
</script>
</body>
</html>
I’m not reach the ‘alert’ code.
Validation working perfectly. After I enter valid card (4111…) and execute my event (using console):
window.dispatchEvent(new Event('requestPayment'))
the error comes.
My code evolve from yesterday, but I sure in 50% that it was working.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:13 (4 by maintainers)
Top GitHub Comments
You’ll receive that error if you attempt to run this code over the file protocol instead of on a webserver.
If you have npm installed on your machine, you can run that same code over a simple webserver, and it will not error.
By default, it should run it on localhost:8080, if you try the same thing, then it should work.
@crookedneighbor My Repo is here
But I just figured out the problem and fixed it. My code was un-mounting the dropin container then replace it with a loader when credit card is submitted.
So you were right before, the console error and the problem I was facing were unrelated.
Gratias…