Skip to content

Instantly share code, notes, and snippets.

@PayHereDevs
Created July 19, 2022 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PayHereDevs/b09c0179e24a893e9fdfe40105f16bc6 to your computer and use it in GitHub Desktop.
Save PayHereDevs/b09c0179e24a893e9fdfe40105f16bc6 to your computer and use it in GitHub Desktop.
# Set PayHere as first
DESIRED_GATEWAY_ORDER = [
"PayHere Payment Gateway"
]
# ================================ Script Code (do not edit) ================================
# ================================================================
# ReorderGatewaysCampaign
#
# Reorders gateways into the entered order
# ================================================================
class ReorderGatewaysCampaign
def initialize(desired_order)
@desired_order = desired_order.map { |item| item.downcase.strip }
end
def run(cart, payment_gateways)
payment_gateways.sort_by! { |payment_gateway| @desired_order.index(payment_gateway.name.downcase.strip) || Float::INFINITY }
end
end
CAMPAIGNS = [
ReorderGatewaysCampaign.new(DESIRED_GATEWAY_ORDER),
]
CAMPAIGNS.each do |campaign|
campaign.run(Input.cart, Input.payment_gateways)
end
Output.payment_gateways = Input.payment_gateways
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment