Created
July 19, 2022 06:38
-
-
Save PayHereDevs/b09c0179e24a893e9fdfe40105f16bc6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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