importdata

Spree : oauth : Import Shipping/Billing Address along with PaymentSource from Doorkeeper app

If you already have billing/shipping address and payment info of the store in the OAuth provider [eg. some app with Doorkeeper]; and you don’t want to let your users go through  the hassle to fill the form all over again, then, you can reuse the data. For this, you need to return the info along with user info from the OAuth provider in the response.

# in /app/models/spree/user_decorator.rb
class << self
  def from_omniauth(auth_data)
    spree_user = get_or_set_user(auth_data)

    # Extract address info from the payload and update
    #  can update only shipping or both address with same data
    set_shipping_address(spree_user, auth_data) if spree_user.ship_address.nil?
    set_billing_address (spree_user, auth_data) if spree_user.bill_address.nil?
    
    # You might also import PaymentSource info from parent app
    #   Ex: User has already submitted payment info [CreditCard info] and
    #   and you have Stripe PaymentSource Id, then you can import the data
    #   along with other info. I recommend you to use HTTPS for this. 
    set_payment_source(spree_user, auth_data) if spree_user.payment_sources.blank?
 
    # Set user's role; say in parent app the user is Admin, then you
    #  might want to set that user as an Admin in child app as well.
    #  See the function definition below
    set_roles(spree_user, auth_data)
    
    # Need to return the user object
    spree_user
  end

  private
  # all the methods assisting 'from_omniauth' will go below here

Continue reading

Rails : Spree : Get the gateway and other payment information

This post covers tips how you can get the payment objects related to particular order / line items.

line_item = order.line_items.first
payments = order.payments
payment = payment.first
payment_method = payment.payment_method
#<Spree::Gateway::StripeGateway:0x0000000ea51b68
payment.payment_source
=> #<Spree::CreditCard:0x0000000e795190
 id: 5,
 month: "12",
 year: "2019",
 cc_type: "visa",
 last_digits: "4242",
 address_id: nil,
 gateway_customer_profile_id: "cus_83nlvzTDq8eJln",
 gateway_payment_profile_id: "card_17ngACBFSOv6rFJZVfRZYpVT",
 created_at: Fri, 11 Mar 2016 02:38:05 UTC +00:00,

Get all charge objects

Now since Spree::Stripe uses active merchant and it creates separate customer in stripe for every order, so you can get the charge object like

Stripe::Customer.retrieve(‘cus_83nlvzTDq8eJln’).charges

Get single Charge Object

order.payments.first.response_code
# => ch_17pzjwBFSOv6rFJZBbd3YNuS

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Spree : EMail Configuration

Introduction

As this has been extracted, please be sure to add spree_mail_settings to your Gemfile before proceeding if you desire this behavior.

Make sure you run ‘rake deface:precompile’ in production to see the changes in effect.

The configurable components of your Spree site are managed in the Mail Method Settings panel. You can reach this by going first to the Admin Interface, clicking “Configuration” and then “Mail Method Settings”.

Mail Method Settings

Enable Mail Delivery

Checking the “Enable Mail Delivery” option will cause all of the confirmation and notification emails the Spree shopping cart system generates to be sent. You may want to disable this option if you want to test other functionality of the store without sending bogus emails.

Send Mails As

Set this to the email address you want to use as the “From” line on emails that are auto-generated by your store.

Send Copy of All Mails To

You may want to keep track of the emails your store sends, especially if you are newly launching your e-commerce business. If so, you can configure the system to send a copy of all confirmation and notification emails to the email address you input for this setting.

Intercept Email Address

Setting this option causes any notification emails to be re-routed to the email address you declare.

SMTP Settings

The SMTP Mail Method settings allow you to fully configure your Spree store’s server to send out email messages via SMTP – Simple Mail Transfer Protocol. A full explanation of how SMTP works is beyond the scope of this user guide, but any changes you or your site’s developer need to make can be done through this area of your Admin Interface.

 

 

Sources:

https://guides.spreecommerce.com/user/configuring_mail_methods.html

spree-commerce-integration-service

Rails : Spree in production [Deface stuffs]

Spree In production

You need to take these things into consideration while deploying your spree app to production. Like, the login button/link might not appear even when your app is up and running. Or may appear twice.

Deface supports precompiling where all overrides are loaded and applied to the original views and the resulting templates are then saved to your application’s app/compiled_views directory. To precompile run:

 $ bundle exec rake deface:precompile

It’s important to disable Deface once precompiling is used to prevent overrides getting applied twice. To disable add the following line to your application’s production.rb file:

config.deface.enabled = false

Additionally,

After every deploy to production you will face this issue and you manually have to recompile the overrides. Its so cumbersome and annoying to do it every time. So I would prefer to make a Capistrano recipe and inject it to the deployment workflow.

There are two ways to execute the recipe

  • You can re-compile every time
  • You can once recompile in `shared` folder and symlink every time. You can invoke the task if there is change in the overrides.

 

namespace :deface do
  task :precompile do
    SSHKit.config.command_map[:rake] = "./bin/rake"

    on roles(:web) do
      set :current_path, "#{fetch(:deploy_to)}/current/"
      within fetch(:current_path) do
        with rails_env: fetch(:rails_env) do
          execute :rake, 'deface:precompile'
        end
      end
    end
  end
end

# in deploy.rb
before 'deploy:restart', 'deface:precompile'

NOTE: You can also use precompiling in development mode. Make sure you restart the application server every time you precompile the overrides.