UNABLE TO CHANGE PAYMENT METHOD NAME (EXCEPT FIRST PAYMENT PROVIDER) USING SCRIPT EDITOR

UNABLE TO CHANGE PAYMENT METHOD NAME (EXCEPT FIRST PAYMENT PROVIDER) USING SCRIPT EDITOR

Sanket_Patel
Shopify Partner
20 0 2

There is bug in Shopify script editor for Payments script. 

I wanted to change name of payment gateway. My script is working correctly for 1st payment gateway name, BUT.. I want to change name of 3rd gateway. It is not working. 

 

Below is actual order of payment gateway : 

POLi Internet Banking
Zip - Buy now, pay later
Merchant Warrior Card Payments
 
Below is the code of script. It does not gives expected outside. (It do not change name of payment gateway - Merchant Warrior Card Payments ) 
I have printed names using "puts" & change name code line is executing, still it does not works. 

But.. when I tried "POLi Internet Banking" & it successfully changed its name. As it is FIRST payment gateway. 
 

 

CHANGE_GATEWAYS_NAME = [
  {
    gateway_match_type: :exact,
    gateway_names: ["Merchant Warrior Card Payments"],
    newname: "Secure Card Payments"
  },
]

# ================================ Script Code (do not edit) ================================
# ================================================================
# GatewayNameSelector
#
# Finds whether the supplied gateway name matches any of the
# entered names.
# ================================================================
class GatewayNameSelector
  def initialize(match_type, gateway_names)
    @comparator = match_type == :exact ? '==' : 'include?'
    @gateway_names = gateway_names.map { |name| name.downcase.strip }
  end

  def match?(payment_gateway)
    @gateway_names.any? { |name| payment_gateway.name.downcase.strip.send(@comparator, name) }
  end
end

# ================================================================
# ChangeNameGatewaysCampaign
# ================================================================
class ChangeNameGatewaysCampaign
  def initialize(campaigns)
    @campaigns = campaigns
  end

  def run(cart, payment_gateways)
    @campaigns.each do |campaign|
      
      gateway_name_selector = GatewayNameSelector.new(
        campaign[:gateway_match_type],
        campaign[:gateway_names],
      )

      payment_gateways.each do |payment_gateway|
        if gateway_name_selector.match?(payment_gateway)
          payment_gateway.change_name(campaign[:newname])
        end
      end
    end
  end
end

CAMPAIGNS = [
  ChangeNameGatewaysCampaign.new(CHANGE_GATEWAYS_NAME),
]

CAMPAIGNS.each do |campaign|
  campaign.run(Input.cart, Input.payment_gateways)
end

Output.payment_gateways = Input.payment_gateways

 

 
 
Can anyone please help ? Shopify support specialist, please.  
 
Freelancer | Software Developer | Shopify Customization Guru | Shopify Public App Creator | sanket972528@gmail.com | https://sannket.com
Replies 5 (5)

m8th
Shopify Partner
13 5 11

hi

 

I have the same problem, Plus Support told me the following:

 

If you have tried renaming the payment gateway and it revert back to its original name, then it is likely something potentially contractual with the payment gateway which is preventing the gateway from being renamed. And this is an expected behaviour which Shopify does not have control over. If you'd like to clarify this, you may reach out to the payment gateway provider to see if they can confirm that for you.

RTFM!
Sanket_Patel
Shopify Partner
20 0 2

Thank you @m8th . Yes I got similar answer from support. 

I posted this question before receiving their reply.

Problem was that, SAME code was working for SAME gateway before that day. Never mind.  

I believe, Shopify should have mention this kind of behavior/conditional things on their help page. 

On this page https://help.shopify.com/en/manual/checkout-settings/script-editor/examples/payment-gateway-scripts they say it's possible. 

Sanket_Patel_0-1663133887533.png

 

 

 

Freelancer | Software Developer | Shopify Customization Guru | Shopify Public App Creator | sanket972528@gmail.com | https://sannket.com
nikitastykov
Shopify Partner
2 0 0

Hi, 

 

As per the same exploration on our side, this might be connected to some restrictions for the new integration type - via the new Payment API. Same sample script isn't working with our payment application as well. 

Hope this helps a bit to clarify. 

 

Thanks and regards,

Nikita 

MarianaZ
Tourist
6 0 19

Hello Sanket, have you found a solution to this problem? If so, can you share?

Sanket_Patel
Shopify Partner
20 0 2

@MarianaZ No. there is no solution.

I used JavaScript and did that after page load. Not a good or suggestion but..my client wanted anyhow and it does not  have any side effects. So I did.  

Freelancer | Software Developer | Shopify Customization Guru | Shopify Public App Creator | sanket972528@gmail.com | https://sannket.com