-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathpayment.min.js
More file actions
1 lines (1 loc) · 1.95 KB
/
Copy pathpayment.min.js
File metadata and controls
1 lines (1 loc) · 1.95 KB
1
define(["core/ajax","core/templates","core/modal","core/modal_events","core/str","core/notification"],function(e,t,o,n,r,a){"use strict";function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=i(e),s=i(t),c=i(o),l=i(n),u=i(a);const{call:m}=d.default,h=e=>{const t="sandbox"===e?"https://jstest.authorize.net/v3/AcceptUI.js":"https://js.authorize.net/v3/AcceptUI.js";if(h.currentlyloaded===t)return Promise.resolve();if(h.currentlyloaded){const e=document.querySelector(`script[src="${h.currentlyloaded}"]`);e&&e.parentNode.removeChild(e)}const o=document.createElement("script");return new Promise(e=>{o.onload=()=>e(),o.setAttribute("src",t),o.setAttribute("charset","utf-8"),document.head.appendChild(o),h.currentlyloaded=t})};return h.currentlyloaded="",{authorizeNetPayment:function(e,t){const o=document.getElementById(`enrolbutton-${e}`);o&&o.addEventListener("click",async()=>{let o;try{const n=await(e=>m([{methodname:"moodle_authorizedotnet_get_config_for_js",args:{instanceid:e}}])[0])(e),a=await s.default.render("enrol_authorizedotnet/authorizedotnet_button",{apiloginid:n.apiloginid,clientkey:n.publicclientkey});o=await c.default.create({title:r.getString("pluginname","enrol_authorizedotnet"),body:a,show:!0,removeOnClose:!0}),await h(n.environment),window.responseHandler=function(n){if(o.getRoot().on(l.default.outsideClick,e=>e.preventDefault()),"Error"===n.messages.resultCode){let e="";for(let t=0;t<n.messages.message.length;t++)e+=n.messages.message[t].text+"\n";return u.default.alert(r.getString("error","moodle"),e),void o.hide()}o.setBody(r.getString("authorising","enrol_authorizedotnet")),((e,t,o)=>m([{methodname:"moodle_authorizedotnet_process_payment",args:{instanceid:e,userid:t,opaquedata:JSON.stringify(o)}}])[0])(e,t,n.opaqueData).then(e=>{o.hide(),e.success?window.location.reload():u.default.alert(r.getString("error","moodle"),e.message)}).catch(e=>{u.default.exception(e),o.hide()})}}catch(e){u.default.exception(e),o&&o.hide()}})}}});