Trigger PayPal checkout button click -
how can trigger paypal checkout button click? have website beside credit cards going accept paypal payments , have decided put radio buttons customers choose way customer going pay , paypal checkout button:
paypal checkout button click opens paypal secure window , rest works fine. when customer click 1st radio button want again open paypal secure window i.e. trigger click on paypal checkout button. how can if button appearing in iframe , not able trigger click event of button cross domain? there way trigger checkout button click?
here html code:
<html> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script src="https://www.paypalobjects.com/api/checkout.js"></script> <script type="text/javascript" src="paypal.js"> </script> <body> <div> <span style="vertical-align: 50%"><input id="rd" name="aaa" type="radio"/></span> <div id="paypal-button-container" style="display: inline-block"></div><hr/> <input id="rd1" name="aaa" type="radio"/> </div> </body> </html>
and javascript code:
// paypal.js // render paypal button $(function(){ paypal.button.render({ // set environment //todo: dynamically provide sandbox or production env: 'sandbox', // sandbox | production // paypal client ids - replace own // create paypal app: https://developer.paypal.com/developer/applications/create //todo: dynamically provide clientid client: { sandbox: 'zzzzzz', production: '//todo: provide later' }, // wait paypal button clicked payment: function() { // make client-side call rest api create payment return paypal.rest.payment.create(this.props.env, this.props.client, { transactions: [ { amount: { total: '13.10', currency: 'usd' } } ] }); }, // wait payment authorized customer onauthorize: function(data, actions) { return actions.payment.get().then(function(paymentdata) { $('#paypal-button-container').style.display = 'none'; //hide button //todo: show user payment details //todo: create input hidden fields , set payerid, paymentid, etc..for later authoriza/capture }); }, onclick: function(){ $('#rd').trigger('click'); }, }, '#paypal-button-container'); });
edit: working example suggest site, little bit different need https://developer.paypal.com/demo/checkout/#/pattern/mark
this isn't that's supported paypal button right now. official policy is, click on button should open checkout window.
Comments
Post a Comment