Skip to content

Commit

Permalink
Merge pull request #45 from angelleye/GFB-46-gravity-forms-braintree-…
Browse files Browse the repository at this point in the history
…payments-error-500-on-adding-credit-card-field

Resolve beaintree payment error while using credit card field, GFB-46
  • Loading branch information
kcppdevelopers authored Aug 3, 2023
2 parents f39bf28 + 00b9b33 commit ce74c19
Showing 1 changed file with 43 additions and 18 deletions.
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

0 comments on commit ce74c19

Please sign in to comment.