Skip to content
9 changes: 9 additions & 0 deletions app/models/oms/billing_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "flex_commerce_api/oms/api_base"

module FlexCommerce
module OMS
class BillingAddress < FlexCommerceApi::OMS::ApiBase
belongs_to :customer_order, class_name: "::FlexCommerce::OMS::CustomerOrder"
end
end
end
9 changes: 9 additions & 0 deletions app/models/oms/customer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "flex_commerce_api/oms/api_base"

module FlexCommerce
module OMS
class Customer < FlexCommerceApi::OMS::ApiBase
belongs_to :customer_order, class_name: "::FlexCommerce::OMS::CustomerOrder"
end
end
end
15 changes: 15 additions & 0 deletions app/models/oms/customer_order.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "flex_commerce_api/oms/api_base"
require "flex_commerce_api/api_base"
module FlexCommerce
module OMS
class CustomerOrder < FlexCommerceApi::OMS::ApiBase
has_many :payments, class_name: "::FlexCommerce::OMS::Payments"
has_many :line_items, class_name: "::FlexCommerce::OMS::LineItem"
has_many :discounts, class_name: "::FlexCommerce::OMS::Discount"
has_many :shipping_address, class_name: "::FlexCommerce::OMS::Address"
has_one :billing_address, class_name: "::FlexCommerce::OMS::Address"
has_one :customer, class_name: "::FlexCommerce::OMS::Customer"
has_one :shipping_method, class_name: "::FlexCommerce::OMS::ShippingMethod"
end
end
end
9 changes: 9 additions & 0 deletions app/models/oms/discount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "flex_commerce_api/oms/api_base"

module FlexCommerce
module OMS
class Discount < FlexCommerceApi::OMS::ApiBase
belongs_to :customer_order, class_name: "::FlexCommerce::OMS::CustomerOrder"
end
end
end
9 changes: 9 additions & 0 deletions app/models/oms/line_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "flex_commerce_api/oms/api_base"

module FlexCommerce
module OMS
class LineItem < FlexCommerceApi::OMS::ApiBase
belongs_to :customer_order, class_name: "::FlexCommerce::OMS::CustomerOrder"
end
end
end
9 changes: 9 additions & 0 deletions app/models/oms/payment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "flex_commerce_api/oms/api_base"

module FlexCommerce
module OMS
class Payment < FlexCommerceApi::OMS::ApiBase
belongs_to :customer_order, class_name: "::FlexCommerce::OMS::CustomerOrder"
end
end
end
9 changes: 9 additions & 0 deletions app/models/oms/shipping_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "flex_commerce_api/oms/api_base"

module FlexCommerce
module OMS
class ShippingAddress < FlexCommerceApi::OMS::ApiBase
belongs_to :customer_order, class_name: "::FlexCommerce::OMS::CustomerOrder"
end
end
end
9 changes: 9 additions & 0 deletions app/models/oms/shipping_method.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "flex_commerce_api/oms/api_base"

module FlexCommerce
module OMS
class ShippingMethod < FlexCommerceApi::OMS::ApiBase
belongs_to :customer_order, class_name: "::FlexCommerce::OMS::CustomerOrder"
end
end
end
12 changes: 12 additions & 0 deletions lib/flex_commerce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ module V2
autoload :UnallocateOrder, File.join(FlexCommerce.gem_root, "app", "models", "v2", "unallocate_order")
end

# OMS
module OMS
autoload :BillingAddress, File.join(FlexCommerce.gem_root, "app", "models", "oms", "billing_address")
autoload :CustomerOrder, File.join(FlexCommerce.gem_root, "app", "models", "oms", "customer_order")
autoload :Customer, File.join(FlexCommerce.gem_root, "app", "models", "oms", "customer")
autoload :Discount, File.join(FlexCommerce.gem_root, "app", "models", "oms", "discount")
autoload :LineItem, File.join(FlexCommerce.gem_root, "app", "models", "oms", "line_item")
autoload :Payment, File.join(FlexCommerce.gem_root, "app", "models", "oms", "payment")
autoload :ShippingAddress, File.join(FlexCommerce.gem_root, "app", "models", "oms", "shipping_address")
autoload :ShippingMethod, File.join(FlexCommerce.gem_root, "app", "models", "oms", "shipping_method")
end

# V1 Models
autoload :Address, File.join(gem_root, "app", "models", "address")
autoload :AssetFile, File.join(gem_root, "app", "models", "asset_file")
Expand Down
13 changes: 13 additions & 0 deletions lib/flex_commerce_api/oms/api_base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "flex_commerce_api/base_resource"

module FlexCommerceApi
module OMS
class ApiBase < FlexCommerceApi::BaseResource
def self.endpoint_version
"v1/oms"
end

reconfigure
end
end
end
2 changes: 1 addition & 1 deletion lib/flex_commerce_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module FlexCommerceApi
VERSION = "0.8.3"
VERSION = "0.8.4"
end
43 changes: 43 additions & 0 deletions lib/patches/json_api_client/resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require "json_api_client/version"
if ["1.5.3"].include?(JsonApiClient::VERSION)
require "json_api_client/resource"
module JsonApiClient
class Resource
def save
return false unless valid?

self.last_result_set = if persisted?
self.class.requestor.update(self)
else
self.class.requestor.create(self)
end

if last_result_set.has_errors?
fill_errors
false
else
self.errors.clear if self.errors
mark_as_persisted!
if updated = last_result_set.first
self.attributes = updated.attributes
# This line has been added as part of https://github.com/chingor13/json_api_client/pull/238
self.links.attributes = updated.links.attributes
self.relationships.attributes = updated.relationships.attributes
clear_changes_information
# This line has been added as part of https://github.com/JsonApiClient/json_api_client/pull/285
self.relationships.clear_changes_information
end
true
end
end
end
end
else
raise %q(
Please check these two PRs:
* https://github.com/chingor13/json_api_client/pull/238 (This was released in version 1.5.0)
* https://github.com/JsonApiClient/json_api_client/pull/285 (This hasn't yet been released at the time of writing this)
If both have been merged into the gem version you are using, remove this file (#{__FILE__}).
If not, add the current version to the allowed array at the top of this file.
)
end
14 changes: 7 additions & 7 deletions lib/paypal_express/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
module FlexCommerce
module PaypalExpress
# @class Setup
#
#
# This service authorises the payment via the Paypal gateway
class Auth
include ::Retry
include ::FlexCommerce::PaypalExpress::Api

DEFAULT_CURRENCY = "GBP"

# @initialize
#
# @param {String} token - Paypal token
Expand All @@ -29,9 +29,9 @@ def initialize(cart:, token:, payer_id:, payment_transaction:, gateway_class: ::
def call
process_with_gateway
end

private

attr_accessor :cart, :token, :payer_id, :payment_transaction, :gateway_class

def process_with_gateway
Expand Down Expand Up @@ -63,15 +63,15 @@ def process_with_gateway
def do_express_checkout_payment
Retry.call(no_of_retries: no_of_retires, rescue_errors: ::ActiveMerchant::ConnectionError) {
::NewRelic::Agent.increment_metric('Custom/Paypal/Do_Express_Checkout_Payment') if defined?(NewRelic::Agent)
gateway.order(convert_amount(cart.total), token: token, payer_id: payer_id, currency: DEFAULT_CURRENCY)
gateway.order(convert_amount(payment_transaction.amount), token: token, payer_id: payer_id, currency: DEFAULT_CURRENCY)
}
end


def do_authorization(response)
Retry.call(no_of_retries: no_of_retires, rescue_errors: ::ActiveMerchant::ConnectionError) {
::NewRelic::Agent.increment_metric('Custom/Paypal/Do_Auhtorization') if defined?(NewRelic::Agent)
gateway.authorize_transaction(response.params["transaction_id"], convert_amount(cart.total), transaction_entity: "Order", currency: DEFAULT_CURRENCY, payer_id: payer_id)
gateway.authorize_transaction(response.params["transaction_id"], convert_amount(payment_transaction.amount), transaction_entity: "Order", currency: DEFAULT_CURRENCY, payer_id: payer_id)
}
end

Expand Down
55 changes: 38 additions & 17 deletions lib/paypal_express/generate_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@
module FlexCommerce
module PaypalExpress
# @class GenerateSummary
#
#
# This class is used while setting up the paypal for FE
# It deals with line items total, sub total, tax calculations and
# Also deals with discounted line items and discounts inorder to send to paypal
#
# If gift card was used to pay partial amount and subsequently
# gift card amount was passed, it subtracts gift card amount from total
#

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class also does something for gift cards now; it might need to be updated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It's simply subtracting gift card amount from total amount but I will update it.

class GenerateSummary
include ::FlexCommerce::PaypalExpress::Api
def initialize(cart: , use_tax: false)

def initialize(cart: , use_tax: false, gift_card_amount:)
self.cart = cart
self.use_tax = use_tax
self.gift_card_amount = gift_card_amount
raise "use_tax is not yet supported. FlexCommerce::PaypalExpress::GenerateSummary should support it in the future" if use_tax
end

# @method call
#
#
# @returns an object with subtotal, tax, handling, shipping and items keys
def call
{
Expand All @@ -34,35 +37,35 @@ def call
private

# @method subtotal
#
#
# @returns the sum of line items total. This doesnt include any promotions
def subtotal
items.sum {|i| i[:quantity] * (i[:amount])}
end

# @method total
#
#
# @return amount after converting cart total from pence to pounds
def total
convert_amount(cart.total)
end

# @method tax
#
#
# @returns the sum of total line items tax
def tax
items.sum {|i| i[:tax] * i[:quantity]}
end

# @method handling
#
#
# @returns Payment handling charges, which is 0
def handling
0
end

# @method shipping
#
#
# @returns 0 if cart is eligible for free shipping
# @returns cart.shipping_total, if cart is not eligibl for free shipping
def shipping
Expand All @@ -71,14 +74,14 @@ def shipping
end

# @mthod items
#
# @returns both line items and discounts
#
# @returns both line items and discounts and gift cards
def items
normal_items + discount_items
normal_items + discount_items + gift_cards
end

# @method discounts
#
#
# @returns [] if there are no discounts on cart
# @returns Array containing about the total discount amount, if any applied.
def discount_items
Expand All @@ -95,8 +98,26 @@ def discount_items
]
end

# @method gift_cards
#
# @returns [] if there are no gift cards on cart
# @returns Array containing total gift card amount, if any applied.
def gift_cards
return [] if gift_card_amount.nil? || gift_card_amount.zero?
[
{
name: "Gift card",
number: "NA",
quantity: 1,
amount: convert_amount(BigDecimal(0) - gift_card_amount),
description: "Gift card",
tax: 0
}
]
end

# @method normal_items
#
#
# @returns Object, the normal line items added to cart
# @note these line items unit prices will be without any discounts
def normal_items
Expand All @@ -112,7 +133,7 @@ def normal_items
end
end

attr_accessor :cart, :use_tax
attr_accessor :cart, :use_tax, :gift_card_amount
end
end
end
end
Loading