Have your say in Community Polls: What was/is your greatest motivation to start your own business?

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

Solved

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

specklefarms
Excursionist
37 1 11

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.

Accepted Solution (1)

specklefarms
Excursionist
37 1 11

This is an accepted solution.

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 %}

 

View solution in original post

Replies 5 (5)

MakP
Shopify Partner
33 9 13

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.

 

<table class="table-tabular" style="margin: 1em 0 0 0;">
    <thead>
        <th>Payment Method</th>
        <th>Amount</th>
        <th>Status</th>
    </thead>
    <tbody>
    {% for transaction in transactions %}
        {% if transaction.kind != 'authorization' %}
            <tr>
                <td>
                    {% if transaction.gateway == 'shopify_payments' %}
                        {{ transaction.payment_details.credit_card_company }} ending in {{ transaction.payment_details.credit_card_last_four_digits }}
                    {% else %}
                        {{ transaction.gateway_display_name }}
                    {% endif %}
                </td>
                <td>{{ transaction.amount | money }}</td>
                <td>{{ transaction.status }}</td>
            </tr>
        {% endif %}
    {% endfor %}
    </tbody>
</table>

 

specklefarms
Excursionist
37 1 11

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.

specklefarms
Excursionist
37 1 11

This is an accepted solution.

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 %}

 

hotcardboard
Visitor
1 0 0

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.

specklefarms
Excursionist
37 1 11

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