Answers.Body: <p>You mean the errors of your form? You can access those via <code>paymentForm</code></p>
  
  <pre class="lang-Twig prettyprint-override"><code>{% for attribute, error in paymentForm %}
      {{ attribute }}: {{ dump(error) }}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-02T15:59:21.610Z
Answers.Text: no, I mean from my gateway, like an invalid credit card number or an invalid CVV number
Answers.UserDisplayName: Flying Car 0013
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-02T16:02:41.470Z
Answers.Text: Your gateway does not have a property credit card number, only your payment form has those. And the Payment Form is provided by your gateway. Your gateway can't contain errors, it isn't even validated
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-02T16:06:24.277Z
Answers.Text: No no, what I mean is like coupons. if i want to get any errors on the coupon, i use this: cart.getFirstError('couponCode')
  isn't there something like this: cart.getFirstError('payment')
Answers.UserDisplayName: Flying Car 0013
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-02T16:52:33.880Z
Answers.Text: No that's what the `paymentForm` is for. The errors of your payment have nothing to do with your order
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-02T15:46:08.157Z
Answers.LastActivityDate: 2019-03-02T15:46:08.157Z
Answers.UserDisplayName: Robin Schambach
Answers.Body: <p>When submitting a payment form to the <code>commerce/payments/pay</code> controller action there are three potential sources of error messages.</p>
  
  <p>If you are submitting via a normal form submission (not ajax) you will be able to get access to the errors in the following manner from your template.</p>
  
  <p><strong>General Errors</strong></p>
  
  <p><code>{% set flashError = craft.app.session.getFlash('error') %}</code> For general errors e.g. <code>requireBillingAddressAtCheckout</code> is set to true and there is no billing address on the order.</p>
  
  <hr>
  
  <p><strong>Order Save Errors</strong></p>
  
  <p><code>{% set orderErrors = order.getErrors() %}</code> The order is recalculated and saved during the pay process to make sure something has not changed elsewhere. The order is validated and therefore errors will be returned if there are validation issues.</p>
  
  <hr>
  
  <p><strong>Payment Form Errors</strong></p>
  
  <p><code>{% set paymentFormErrors = paymentForm.getErrors() %}</code> The payment form errors will contain any errors related to the payment form and, dependant on gateway, may also return payment gateway errors.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-22T23:13:15.570Z
Answers.Text: This should be the correct answer I think.
Answers.UserDisplayName: iambriansreed
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-22T23:23:08.280Z
Answers.Text: Also don't forget to dump those errors too.
Answers.UserDisplayName: iambriansreed
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-20T17:35:15.913Z
Answers.LastActivityDate: 2020-05-24T05:50:06.280Z
Answers.LastEditDate: 2020-05-24T05:50:06.280Z
Answers.UserDisplayName: nfourtythree
Answers.Body: <p>I was able to use the "flash message" that's included in their demo templates (shop/_layout/main)</p>
  
  <pre><code>{% set flashNotice = craft.app.session.getFlash('notice') %}
  
  {% if flashNotice %}
      &lt;div class="bg-blue text-white"&gt;
          &lt;div class="container mx-auto px-6 py-4"&gt;
              {{ flashNotice }}
          &lt;/div&gt;
      &lt;/div&gt;
  {% endif %}
  
  {% set flashError = craft.app.session.getFlash('error') %}
  
  {% if flashError %}
      &lt;div class="bg-red text-white"&gt;
          &lt;div class="container mx-auto px-6 py-4"&gt;
              {{ flashError }}
          &lt;/div&gt;
      &lt;/div&gt;
  {% endif %}
  
  {% if cart.errors|length %}
      &lt;div class="bg-red text-white"&gt;
          &lt;div class="container mx-auto px-6 py-4"&gt;
              {% for attribute, errors in cart.errors %}
                  {% if loop.first %}&lt;ul&gt;{% endif %}
                  {% for key, error in errors %}
                      &lt;li&gt;{{ attribute }}: {{ error }}&lt;/li&gt;
                  {% endfor %}
                  {% if loop.last %}&lt;/ul&gt;{% endif %}
              {% endfor %}
          &lt;/div&gt;
      &lt;/div&gt;
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-19T15:50:22.530Z
Answers.LastActivityDate: 2019-10-19T15:50:22.530Z
Answers.UserDisplayName: EDub
Body: <p>I am trying to display the error message coming from the payment gateway ONLY.
  I know I can use</p>
  
  <pre><code>{% set message = craft.app.session.getFlash('error') %}
  {{ message|length ? message }}
  </code></pre>
  
  <p>but commerce returns to me a vague error like this </p>
  
  <blockquote>
    <p>Unable to update cart.</p>
  </blockquote>
  
  <p>If anything happens to the cart, even if it is not the payment. I don't know what the error is, nor does the customer. So is there a way to catch payment errors of the cart only?</p>
  
Tags: <plugin-craftcommerce2><error-handling>
Title: How to display payment gateway error message only
ThreadText: # How to display payment gateway error message only
  
  (Asked by: username_0 on 2019-03-02)
  
  I am trying to display the error message coming from the payment gateway ONLY.
  I know I can use
  
  ```
  {% set message = craft.app.session.getFlash('error') %}
  {{ message|length ? message }}
  
  ```
  
  but commerce returns to me a vague error like this
  
  > Unable to update cart.
  
  If anything happens to the cart, even if it is not the payment. I don't know what the error is, nor does the customer. So is there a way to catch payment errors of the cart only?
  
  **Tags:** plugin-craftcommerce2, error-handling
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2019-03-02. Score: 2 | Accepted answer
  
  You mean the errors of your form? You can access those via `paymentForm`
  
  ```Twig
  {% for attribute, error in paymentForm %}
      {{ attribute }}: {{ dump(error) }}
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: no, I mean from my gateway, like an invalid credit card number or an invalid CVV number  
  > **username_1**: Your gateway does not have a property credit card number, only your payment form has those. And the Payment Form is provided by your gateway. Your gateway can't contain errors, it isn't even validated  
  > **username_0**: No no, what I mean is like coupons. if i want to get any errors on the coupon, i use this: cart.getFirstError('couponCode') isn't there something like this: cart.getFirstError('payment')  
  > **username_1**: No that's what the `paymentForm` is for. The errors of your payment have nothing to do with your order  
  
  ---
  
  ### Answer by username_2 on 2019-10-20. Score: 5
  
  When submitting a payment form to the `commerce/payments/pay` controller action there are three potential sources of error messages.
  
  If you are submitting via a normal form submission (not ajax) you will be able to get access to the errors in the following manner from your template.
  
  **General Errors**
  
  `{% set flashError = craft.app.session.getFlash('error') %}` For general errors e.g. `requireBillingAddressAtCheckout` is set to true and there is no billing address on the order.
  
  ---
  
  **Order Save Errors**
  
  `{% set orderErrors = order.getErrors() %}` The order is recalculated and saved during the pay process to make sure something has not changed elsewhere. The order is validated and therefore errors will be returned if there are validation issues.
  
  ---
  
  **Payment Form Errors**
  
  `{% set paymentFormErrors = paymentForm.getErrors() %}` The payment form errors will contain any errors related to the payment form and, dependant on gateway, may also return payment gateway errors.
  
  > **Comments:**
  > **username_3**: This should be the correct answer I think.  
  > **username_3**: Also don't forget to dump those errors too.  
  
  ---
  
  ### Answer by username_4 on 2019-10-19. Score: 1
  
  I was able to use the "flash message" that's included in their demo templates (shop/\_layout/main)
  
  ```
  {% set flashNotice = craft.app.session.getFlash('notice') %}
  
  {% if flashNotice %}
      <div class="bg-blue text-white">
          <div class="container mx-auto px-6 py-4">
              {{ flashNotice }}
          </div>
      </div>
  {% endif %}
  
  {% set flashError = craft.app.session.getFlash('error') %}
  
  {% if flashError %}
      <div class="bg-red text-white">
          <div class="container mx-auto px-6 py-4">
              {{ flashError }}
          </div>
      </div>
  {% endif %}
  
  {% if cart.errors|length %}
      <div class="bg-red text-white">
          <div class="container mx-auto px-6 py-4">
              {% for attribute, errors in cart.errors %}
                  {% if loop.first %}<ul>{% endif %}
                  {% for key, error in errors %}
                      <li>{{ attribute }}: {{ error }}</li>
                  {% endfor %}
                  {% if loop.last %}</ul>{% endif %}
              {% endfor %}
          </div>
      </div>
  {% endif %}
  
  ```
  
  
  ---
  
  