Use PaymentGatewayException:: createForPayment()

Created on 4 January 2024, 11 months ago
Updated 29 February 2024, 9 months ago

Problem/Motivation

This issue exists to try out πŸ“Œ Make it easy to add payment info to \Drupal\commerce_payment\Exception\PaymentGatewayException Active and implement it if it works as hoped.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Active

Version

1.0

Component

PayPal Checkout

Created by

πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @alexpott
  • πŸ‡¦πŸ‡ΊAustralia elc

    I've patched around this for years because the error message was useless for users. I received UNPROCESSABLE_ENTITY:INSTRUMENT_DECLINED which is effectively a permanent error which came up as "unexpected... try again" which they really shouldn't be. The end-user message was actually contained in the body of the returned response instead of returned "message" - neither of which is given to the user. See full error response below.

    Payment Gateway actually has 3 newer exceptions which provide a little more clarity:

    Drupal\commerce_payment\Exception\DeclineException (extends PaymentGatewayException)
    Drupal\commerce_payment\Exception\HardDeclineException (extends DeclineException)
    Drupal\commerce_payment\Exception\SoftDeclineException (extends DeclineException)
    

    I converted most payment gateway exceptions into either Hard or Soft exceptions and changed the messaging appropriately.

    For the Payment Gateway implementation to be able to set a USEFUL and meaningful error message to the end user would be excellent - the existing hard-coded error message is in Commerce, so it would require changes there.

    When I was coding my work-arounds (hacks), I could see that being able to set the useful returned message and have it printed out instead of the hard-coded messages would be the best way to do it. ie add "get/setUserErrorMessage(translatable $msg)" which would really be given to the user instead of the generic one - fallback to generic if no user message set.

    For reference, this is the full error received from paypal in my case, as the json decoded contents of the GuzzleHttp\Exception\BadResponseException::getResponse()

    Array
    (
        [name] => UNPROCESSABLE_ENTITY
        [details] => Array
            (
                [0] => Array
                    (
                        [issue] => INSTRUMENT_DECLINED
                        [description] => The instrument presented  was either declined by the processor or bank, or it can't be used for this payment.
                    )
    
            )
    
        [message] => The requested action could not be performed, semantically incorrect, or failed business validation.
        [debug_id] => XXXXXXXXXXXXX
        [links] => Array
            (
                [0] => Array
                    (
                        [href] => https://developer.paypal.com/docs/api/orders/v2/#error-INSTRUMENT_DECLINED
                        [rel] => information_link
                        [method] => GET
                    )
    
                [1] => Array
                    (
                        [href] => https://www.paypal.com/checkoutnow?token=XXXXXXXXXXXXXXXXX
                        [rel] => redirect
                        [method] => GET
                    )
    
            )
    )
    
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.0 & MySQL 5.7
    last update 9 months ago
    Composer require failure
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.0 & MySQL 5.7
    last update 9 months ago
    Composer require failure
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.0 & MySQL 5.7
    last update 9 months ago
    Composer require failure
Production build 0.71.5 2024