Order Printer App: Printing Invoice to display Credit Card Brand when using Shopify payments but...

My code from the Legacy version of Order Printer is broken, but I would like to achieve these results. Is this possible without using IF ELSE? Here are the conditions.

If the customer is using Shopify payments, then display the Credit Card Brand.

If all other payment methods, Paypal, Affirm, Gift Card, then display those gateways.

Is this possible? My Legacy code did this, but in the new Order Printer version, it shows “shopify_payments” with the same code.

I am not sure there is a way to accomplish this without the use of if statements. I will admit I’m not 100% certain about that as I haven’t needed to mess with transaction lines too frequently.

Here is an example code snippet that does what your asking using if statements. Obviously it would need to be modified to fit your specific template, but it might be a good jumping off point if no one is aware of a way to accomplish this without the if statements.


    {% for transaction in transactions %}
        {% if transaction.kind != 'authorization' %}
            
        {% endif %}
    {% endfor %}
    

| Payment Method | Amount | Status |
| - | - | - |
| <br>                    {% if transaction.gateway == 'shopify_payments' %}<br>                        {{ transaction.payment_details.credit_card_company }} ending in {{ transaction.payment_details.credit_card_last_four_digits }}<br>                    {% else %}<br>                        {{ transaction.gateway_display_name }}<br>                    {% endif %}<br>                 | {{ transaction.amount | money }} | {{ transaction.status }} |

It seems that I am stuck with using If-Then statements, which is fine.

However, this code isn’t working for me and now a second problem appeared where it won’t display correctly if a Credit Card and a Gift Card were both used for the order. It only shows the Credit Card.

I figured out my own solution by asking ChatGPT. This is working well for me now. The formatting is a bit sloppy with the first line not correctly indented.

{% assign shopify_payments_gateway = "shopify_payments" %}
                {% assign payment_method_printed = false %}
                
                {% for transaction in order.transactions %}
                  {% if transaction.gateway == shopify_payments_gateway %}
                    {{ transaction.payment_details.credit_card_company }}
                    {% assign payment_method_printed = true %}
                    {% break %}
                  {% endif %}
                {% endfor %}
                
                {% if payment_method_printed == false %}
                  {{ transactions[0].gateway_display_name }}
                {% endif %}

Does this code require a certainly level of Shopify plan to work? I have the Shopify Basic plan and this code, when inserted, doesn’t seem to produce anything.

I have no idea. Maybe post your code for the Receipt Printer and maybe someone here can help.