app/views/spree/checkout/payment/_affirm.html.erb in spree_affirm-0.2.22 vs app/views/spree/checkout/payment/_affirm.html.erb in spree_affirm-0.2.30

- old
+ new

@@ -1,33 +1,29 @@ -<div class="affirm-learn-more-section"> - <%= render partial: 'spree/checkout/affirm/learn_more' %> -</div> - <script> (function(){ /* only include this setup once */ if (!window.AffirmPaymentMethods) { /*****************************************************\ Include the affirm js snippet \*****************************************************/ var _affirm_config = { public_api_key: "<%= payment_method.preferred_api_key %>", - script: "https://<%= payment_method.preferred_server %>/js/v2/affirm.js" + script: "https://<%= payment_method.preferences[:test_mode] ? 'cdn1-sandbox.affirm.com' : 'cdn1.affirm.com' %>/js/v2/affirm.js" }; (function(l,g,m,e,a,f,b){var d,c=l[m]||{},h=document.createElement(f),n=document.getElementsByTagName(f)[0],k=function(a,b,c){return function(){a[b]._.push([c,arguments])}};c[e]=k(c,e,"set");d=c[e];c[a]={};c[a]._=[];d._=[];c[a][b]=k(c,a,b);a=0;for(b="set add save post open empty reset on off trigger ready setProduct".split(" ");a<b.length;a++)d[b[a]]=k(c,e,b[a]);a=0;for(b=["get","token","url","items"];a<b.length;a++)d[b[a]]=function(){};h.async=!0;h.src=g[f];n.parentNode.insertBefore(h,n);delete g[f];d(g);l[m]=c})(window,_affirm_config,"affirm","checkout","ui","script","ready"); /*****************************************************\ set the shared checkout data \*****************************************************/ affirm.checkout({ total: <%= (@order.total * 100).to_i %>, currency: "USD", tax_amount: <%= (@order.additional_tax_total * 100).to_i %>, - checkout_id: "<%= @order.number %>", + order_id: "<%= @order.number %>", discount_code: "<%= @order.coupon_code %>", - shipping_type: "<%= @order.shipments.first.shipping_method.name if @order.shipments %>", + shipping_type: "<%= @order.shipments.first.shipping_method.name if @order.shipments.exists? %>", shipping_amount: <%= (@order.shipment_total * 100).to_i %>, shipping: { name: { full: "<%= @order.ship_address.full_name %>", @@ -56,14 +52,18 @@ zipcode: "<%= @order.bill_address.zipcode %>", } }, + metadata: { + "platform_type": "Spree Commerce", + "platform_version": "<%= Spree.version %>", + "platform_affirm": "<%= Spree::Gateway::Affirm.version %>", + }, + meta: { source: { - client_name: "spree_affirm", - version: "<%= Spree::Gateway::Affirm.version %>", data: { <% if spree_current_user %> order_count: "<%= spree_current_user.orders.complete.count %>", account_created: "<%= spree_current_user.created_at %>", @@ -71,11 +71,10 @@ last_order_date: "<%= spree_current_user.orders.complete.last.completed_at %>", <% end %> <% end %> is_logged_in: <%= !!spree_current_user %>, - spree_version: "<%= Spree.version %>" } } }, merchant: { @@ -122,56 +121,63 @@ /* wait for the DOM to be ready */ affirm.ui.ready(function(){ $(function() { /*****************************************************\ + change the payment method name + \*****************************************************/ + + $( ".payment-option" ).each(function() { + + if($( this )[0].innerText === "Affirm"){ + + $( this )[0].lastChild.data = "Affirm Monthly Payments"; + } + }); + + /*****************************************************\ setup loading and cancel events for the form \*****************************************************/ + affirm.checkout.on("cancel", function(){ $("#checkout_form_payment input.disabled") .attr("disabled", false) .removeClass("disabled"); }); - var button_text = $("#checkout_form_payment input").val(); - - $("#checkout_form_payment input[type='submit']").on("loading", function(){ - button_text = $(this).val(); - $(this).val("Loading..."); - }) - - .on("done_loading", function(){ - $(this).val(button_text); - }); - - - /*****************************************************\ handle continue button clicks with .open() \*****************************************************/ $('#checkout_form_payment').submit(function(e){ var checkedPaymentMethod = $('div[data-hook="checkout_payment_step"] input[type="radio"]:checked').val(); if (window.AffirmPaymentMethods[checkedPaymentMethod]) { + var $submit_button = $(this).find("input[type='submit']"); // update with checkout method details affirm.checkout(window.AffirmPaymentMethods[checkedPaymentMethod]); - // show the loading message - $submit_button.trigger("loading"); - // submit the checkout affirm.checkout.open({ target: $submit_button }); e.preventDefault(); return false; } }); }); + + /*****************************************************\ + remove the payment source empty box from UI + \*****************************************************/ + $(document).on('click', '#checkout_form_payment' + , function (event) { + if($('div[data-hook="checkout_payment_step"] input[type="radio"]:checked')[0].parentNode.outerText === "Affirm Monthly Payments") $('.payment-sources').hide(); + } + ) }); window.AffirmPaymentMethods = {}; } @@ -180,11 +186,10 @@ set the product/button specific data to be used when the continue button is directly clicked \*****************************************************/ window.AffirmPaymentMethods["<%= payment_method.id %>"] = { - public_api_key: "<%= payment_method.preferred_api_key %>", - financial_product_key: "<%= payment_method.preferred_product_key %>" + public_api_key: "<%= payment_method.preferred_api_key %>" }; - }()); + </script>