Class: TradoStripeModule::Striper
- Inherits:
-
Object
- Object
- TradoStripeModule::Striper
- Defined in:
- lib/trado_stripe_module/striper.rb
Class Method Summary collapse
-
.complete(order, session, ip_address) ⇒ Object
Creates a charge for the Stripe API; receives a response and in turn creates the relevant transaction records, sends a confirmation email and redirects the user.
-
.failed(error, order) ⇒ Object
When an order has failed to complete, a new transaction record is created with a logged status reason.
-
.successful(charge, order) ⇒ Object
Upon successfully completing an order with a Stripe payment option a new transaction record is created, stock is updated for the relevant SKU.
Class Method Details
.complete(order, session, ip_address) ⇒ Object
Creates a charge for the Stripe API; receives a response and in turn creates the relevant transaction records, sends a confirmation email and redirects the user.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/trado_stripe_module/striper.rb', line 12 def self.complete order, session, ip_address order.transfer(order.cart) charge = Stripe::Charge.create( amount: Store::Price.new(price: order.gross_amount, tax_type: 'net').singularize, currency: Store.settings.currency_code, customer: order.stripe_customer_id, description: "Order ID ##{order.id} | #{order.billing_address.full_name} | #{order.email}", metadata: Hash[ *order.order_items.collect { |item| [ "order_item_#{item.id}", "#{item.product.name} - #{item.sku.full_sku}" ] }.flatten ], statement_descriptor: Store.settings.stripe_statement_descriptor ) if charge.paid TradoStripeModule::Striper.successful(charge, order) Payatron4000.destroy_cart(session) Payatron4000.decommission_order(order) order.reload Mailatron4000::Orders.confirmation_email(order) return Rails.application.routes.url_helpers.success_orders_url(host: Trado::Application.config.action_mailer.[:host]) end rescue Stripe::CardError => e body = e.json_body err = body[:error] TradoStripeModule::Striper.failed(err, order) order.reload Mailatron4000::Orders.confirmation_email(order) return Rails.application.routes.url_helpers.failed_orders_url(host: Trado::Application.config.action_mailer.[:host]) end |
.failed(error, order) ⇒ Object
When an order has failed to complete, a new transaction record is created with a logged status reason
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/trado_stripe_module/striper.rb', line 63 def self.failed error, order Transaction.new( :fee => 0, :gross_amount => order.gross_amount, :order_id => order.id, :payment_status => 'failed', :transaction_type => 'Credit', :tax_amount => order.tax_amount, :stripe_charge_id => nil, :payment_type => 'stripe', :net_amount => order.net_amount, :status_reason => error[:message], :error_code => error[:code].to_i ).save(validate: false) Payatron4000.increment_product_order_count(order.products) end |
.successful(charge, order) ⇒ Object
Upon successfully completing an order with a Stripe payment option a new transaction record is created, stock is updated for the relevant SKU
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/trado_stripe_module/striper.rb', line 43 def self.successful charge, order Transaction.new( :fee => charge.application_fee, :order_id => order.id, :payment_status => 'completed', :transaction_type => 'Credit', :tax_amount => order.tax_amount, :stripe_charge_id => charge.id, :payment_type => 'stripe', :net_amount => order.net_amount, :gross_amount => order.gross_amount ).save(validate: false) Payatron4000.update_stock(order) Payatron4000.increment_product_order_count(order.products) end |