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

Resolve beaintree payment error while using credit card field, GFB-46 #45

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 43 additions & 18 deletions includes/class-angelleye-gravity-braintree-creditcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,49 @@ public function get_field_input( $form, $value = '', $entry = null ) {
<input type="hidden" id="nonce" name="payment_method_nonce"/>
</div>
<script type="text/javascript">
const form = document.getElementById('gform_<?php echo $form_id; ?>');

braintree.dropin.create({
authorization: '<?php echo $clientToken;?>',
container: '#dropin-container'
}, (error, dropinInstance) => {
if (error) console.error(error);

form.addEventListener('submit', event => {
event.preventDefault();

dropinInstance.requestPaymentMethod((error, payload) => {
if (error) console.error(error);
document.getElementById('nonce').value = payload.nonce;
form.submit();
});
});
});
// const form = document.getElementById('gform_<?php echo $form_id; ?>');
if(typeof braintree === 'undefined') {
// console.log("Braintree is not loaded yet. Loading...");
var script = document.createElement('script');
script.onload = function () {
// console.log("Braintree is now loaded.");
braintree.dropin.create({
authorization: '<?php echo $clientToken;?>',
container: '#dropin-container'
}, (error, dropinInstance) => {
if (error) console.error(error);

document.getElementById('gform_<?php echo $form_id; ?>').addEventListener('submit', event => {
event.preventDefault();

dropinInstance.requestPaymentMethod((error, payload) => {
if (error) console.error(error);
document.getElementById('nonce').value = payload.nonce;
document.getElementById('gform_<?php echo $form_id; ?>').submit();
});
});
});
};
script.src = 'https://js.braintreegateway.com/web/dropin/1.26.0/js/dropin.min.js';
document.head.appendChild(script);
} else {
braintree.dropin.create({
authorization: '<?php echo $clientToken;?>',
container: '#dropin-container'
}, (error, dropinInstance) => {
if (error) console.error(error);

document.getElementById('gform_<?php echo $form_id; ?>').addEventListener('submit', event => {
event.preventDefault();

dropinInstance.requestPaymentMethod((error, payload) => {
if (error) console.error(error);
document.getElementById('nonce').value = payload.nonce;
document.getElementById('gform_<?php echo $form_id; ?>').submit();
});
});
});
}
</script>
<?php
$html = ob_get_contents();
Expand Down