1jQuery( document ).on( 'wpec_before_render_button', function( e, handler ) { 2 3 if ( ! handler.data.subscription ) { 4 return; 5 } 6 7 if ( ! handler.data.subscription.plan_id ) { 8 9 // Perform a server-side request for a plan id. 10 jQuery.ajax( { 11 async : false, 12 type: "POST", 13 url: ppecFrontVars.ajaxUrl, 14 data: { 15 action: "wpec_sub_get_plan_id", 16 data: handler.data, 17 nonce: WPECSub.nonce, 18 } 19 } ) 20 .done( function( response ) { 21 if ( response.success ) { 22 handler.data.subscription.plan_id = response.data; 23 return !! response.data; 24 } else { 25 handler.data.errors = WPECSub.reqError + '<br />' + response.data[0].message; 26 } 27 } ) 28 .fail( function() { 29 handler.data.errors = WPECSub.reqError; 30 } ); 31 } 32 33 if ( ! handler.data.subscription.plan_id ) { 34 return; 35 } 36 37 // Remove createOrder method in favor of createSubscription 38 delete handler.buttonArgs.createOrder; 39 40 // Replace default product price with a recurring price. 41 handler.data.price = handler.data.subscription.recur_price; 42 43 // Setup Subscription 44 handler.buttonArgs.createSubscription = function( data, actions ) { 45 handler.calcTotal(); 46 var sub_args = { 47 'plan_id': handler.data.subscription.plan_id, 48 'quantity': handler.data.quantity, 49 'shipping_amount': { 50 'currency_code': handler.data.currency, 51 'value': parseFloat( handler.data.shipping || 0 ) 52 }, 53 'plan': { 54 'billing_cycles': [ { 55 'sequence' : handler.data.subscription.trial_period > 0 ? 2 : 1, 56 'pricing_scheme' : { 57 'fixed_price' : { 58 'value' : handler.data.newPrice, 59 'currency_code' : handler.data.currency 60 } 61 } 62 } ], 63 //'payment_preferences': {}, 64 'taxes': { 65 'percentage': ! handler.data.tax ? 0 : handler.data.tax, 66 'inclusive': false 67 } 68 } 69 }; 70 71 return actions.subscription.create( sub_args ); 72 }; 73 74 handler.buttonArgs.onApprove = function( data, actions) { 75 jQuery( 'div.wp-ppec-overlay[data-ppec-button-id="' + handler.data.id + '"]' ).css( 'display', 'flex' ); 76 actions.subscription.get().then( function( details ) { 77 var payment = {}; 78 payment.subscription = details; 79 payment.order = { 80 id: data.orderID 81 }; 82 payment.payer = details.subscriber; 83 handler.processPayment( payment, 'wpec_process_subscription' ); 84 } ); 85 }; 86 87} ); 88 89jQuery( document ).on( 'wpec_after_update_all_amounts', function( e, handler ) { 90 if ( ! handler.data.subscription ) { 91 return; 92 } 93 94 var price_cont = jQuery( '.wp-ppec-shortcode-container[data-ppec-button-id="' + handler.data.id + '"]' ).closest( '.wpec-product-item, .wpec-post-item' ).find( '.wpec-price-container' ); 95 if ( price_cont.length > 0 ) { 96 var tAmount = 0; 97 var trial = price_cont.find( '.wpec-trial-price-amount' ); 98 if ( trial.length > 0 ) { 99 tAmount = calcAmount( handler.data.subscription.trial_price ); 100 if ( tAmount > 0 ) { 101 trial.html( handler.formatMoney( tAmount ) ); 102 } 103 } 104 var price = price_cont.find( '.wpec-price-amount' ); 105 if ( price.length > 0 ) { 106 tAmount = calcAmount( handler.data.price ); 107 price.html( handler.formatMoney( tAmount ) ); 108 } 109 var newPrice = price_cont.find( '.wpec-new-price-amount' ); 110 if ( newPrice.html() ) { 111 tAmount = calcAmount( handler.data.newPrice ); 112 newPrice.html( handler.formatMoney( tAmount ) ); 113 } 114 115 function calcAmount( price ) { 116 var itemSubt = parseFloat( price ); 117 var quantity = parseInt( handler.data.quantity ); 118 var tax = 0; 119 var shipping = 0; 120 if ( handler.data.tax ) { 121 tax = itemSubt * handler.data.tax / 100; 122 } 123 if ( handler.data.shipping ) { 124 shipping = parseFloat( handler.data.shipping ); 125 } 126 127 itemSubt = handler.PHP_round( ( itemSubt + tax ) * quantity + shipping, handler.data.dec_num ); 128 return itemSubt; 129 }; 130 } 131} );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.