You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Below my full file, besides the changes above everything else is the same. Store Credits working fine with only these small tweaks to express and payment details method
# app/controllers/spree/paypal_controller_decorator.rbSpree::PaypalController.class_evaldodefexpressorder=current_order || raise(ActiveRecord::RecordNotFound)items=order.line_items.map(&method(:line_item))additional_adjustments=order.all_adjustments.additionaltax_adjustments=additional_adjustments.taxshipping_adjustments=additional_adjustments.shippingadditional_adjustments.eligible.eachdo |adjustment|
# Because PayPal doesn't accept $0 items at all. See #10# https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECCustomizing# "It can be a positive or negative value but not zero."nextifadjustment.amount.zero?nextiftax_adjustments.include?(adjustment) || shipping_adjustments.include?(adjustment)items << {Name: adjustment.label,Quantity: 1,Amount: {currencyID: order.currency,value: adjustment.amount}}endiforder.using_store_credit?items << {Name: "Store Credits",Quantity: 1,Amount: {currencyID: order.currency,value: order.total_applied_store_credit * -1}}endpp_request=provider.build_set_express_checkout(express_checkout_request_details(order,items))beginpp_response=provider.set_express_checkout(pp_request)ifpp_response.success?redirect_toprovider.express_checkout_url(pp_response,useraction: 'commit')elseflash[:error]=Spree.t('flash.generic_error',scope: 'paypal',reasons: pp_response.errors.map(&:long_message).join(" "))redirect_tocheckout_state_path(:payment)endrescueSocketErrorflash[:error]=Spree.t('flash.connection_failed',scope: 'paypal')redirect_tocheckout_state_path(:payment)endenddefpayment_detailsitems# This retrieves the cost of shipping after promotions are applied# For example, if shippng costs $10, and is free with a promotion, shipment_sum is now $10shipment_sum=current_order.shipments.map(&:discounted_cost).sum# This calculates the item sum based upon what is in the order total, but not for shipping# or tax. This is the easiest way to determine what the items should cost, as that# functionality doesn't currently exist in Spree coreitem_sum=current_order.total - shipment_sum - current_order.additional_tax_total - current_order.total_applied_store_creditifitem_sum.zero?# Paypal does not support no items or a zero dollar ItemTotal# This results in the order summary being simply "Current purchase"{OrderTotal: {currencyID: current_order.currency,value: current_order.total}}else{OrderTotal: {currencyID: current_order.currency,value: current_order.total - current_order.total_applied_store_credit},ItemTotal: {currencyID: current_order.currency,value: item_sum},ShippingTotal: {currencyID: current_order.currency,value: shipment_sum,},TaxTotal: {currencyID: current_order.currency,value: current_order.additional_tax_total},ShipToAddress: address_options,PaymentDetailsItem: items,ShippingMethod: "Shipping Method Name Goes Here",PaymentAction: "Sale"}endendend
The text was updated successfully, but these errors were encountered:
Thank you for detailing this solution! I just spent about an hour looking into how to monkey patch a fix in and it is good to see that my solution matches yours!
You just need to edit the item_sum to consider the applied store credits (current_order.total_applied_store_credit)
better_spree_paypal_express/app/controllers/spree/paypal_controller.rb
Line 117 in 962a789
And add and item with the store credit discount after adding items for all other adjustments
better_spree_paypal_express/app/controllers/spree/paypal_controller.rb
Line 28 in 4f9a187
Below my full file, besides the changes above everything else is the same. Store Credits working fine with only these small tweaks to express and payment details method
The text was updated successfully, but these errors were encountered: