We've run into a few instances where it would be nice to be able to alter the TransactionRequest object before it is sent off on a request. Here are a couple of examples:

1. We use a name field for the billing name. Would be nice to be able to plug that set of values into the name fields on the TransactionRequest.
2. We hit the hard line item limit on a single transaction (30?). It would be nice to be able to implement a strategy to prevent these orders from erring out.

I see there are @todos about making this happen. So I'm hopeful that you all are open to the idea. I'm happy to submit a patch for the AcceptJS payment gateway. We don't use the Echeck or VisaCheckout so I feel less comfortable doing so for those. Thanks!

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lkacenja created an issue. See original summary.

lkacenja’s picture

Here is my first stab. I figured creating an event for the payment creation and refund operations might be a good way to go. Thanks.

greggles’s picture

Status: Active » Needs review

Just updating status since there's a patch here.

lkacenja’s picture

I realized that you aren't able to change the customer information like firstName and lastName or phoneNumber when creating a transaction. So I added a second set of events that are fired off when you create or update a PaymentProfile. I've attached a patch. Thanks!

nathaniel’s picture

Thanks for the patch! Needed this to update order description in the email from authnet.

(previously: x_description, default: Goods or Services)

zengenuity’s picture

Re-roll.

Edit - Bad patch on this one. Fixing it.

zengenuity’s picture

Corrected re-roll patch.

The last submitted patch, 6: commerce_authnet-transactionrequest-alterable-3089783-6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mglaman’s picture

Looks great, to me. I'd like to reduce backward compatibility problems by not overriding the constructor and create methods.

  1. +++ b/src/Event/AuthorizeNetEvents.php
    @@ -0,0 +1,48 @@
    +  const CREATE_TRANSACTION_REQUEST = 'commerce_authnet.transaction_request.create';
    

    nit: it's the CreateTransactionRequest resource, so let's name it create_transaction_request

  2. +++ b/src/Event/AuthorizeNetEvents.php
    @@ -0,0 +1,48 @@
    +  const REFUND_TRANSACTION_REQUEST = 'commerce_authnet.transaction_request.refund';
    ...
    +  const CREATE_PAYMENT_PROFILE = 'commerce_authnet.payment_profile.create';
    ...
    +  const UPDATE_PAYMENT_PROFILE = 'commerce_authnet.payment_profile.update';
    

    See previous event name nit

  3. +++ b/src/Plugin/Commerce/PaymentGateway/AcceptJs.php
    @@ -54,6 +69,44 @@ use Lcobucci\JWT\Signer\Hmac\Sha256;
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    +    return new static(
    +      $configuration,
    +      $plugin_id,
    +      $plugin_definition,
    +      $container->get('entity_type.manager'),
    +      $container->get('plugin.manager.commerce_payment_type'),
    +      $container->get('plugin.manager.commerce_payment_method_type'),
    +      $container->get('datetime.time'),
    +      $container->get('commerce_price.minor_units_converter'),
    +      $container->get('http_client'),
    +      $container->get('commerce_authnet.logger'),
    +      $container->get('tempstore.private'),
    +      $container->get('commerce_order.adjustment_transformer'),
    +      $container->get('messenger'),
    +      $container->get('event_dispatcher')
    +    );
    +  }
    +
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, PaymentTypeManager $payment_type_manager, PaymentMethodTypeManager $payment_method_type_manager, TimeInterface $time, MinorUnitsConverterInterface $minor_units_converter, ClientInterface $client, LoggerInterface $logger, PrivateTempStoreFactory $private_tempstore, AdjustmentTransformerInterface $adjustment_transformer, MessengerInterface $messenger, EventDispatcherInterface $event_dispatcher) {
    +    parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $payment_type_manager, $payment_method_type_manager, $time, $minor_units_converter, $client, $logger, $private_tempstore, $adjustment_transformer, $messenger);
    +
    +    $this->eventDispatcher = $event_dispatcher;
    +  }
    +
    +    /**
    

    It's not as common, but I'd like to use the "setter" pattern here to prevent a bunch of possible BC nightmare.

    So we'd add setEventDispatcher. And in `create` we'd call parent::create and with that result setEventDispatcher on ourselves.

    No more overridden constructor. No create method BC woes

mglaman’s picture

nit: it's the CreateTransactionRequest resource, so let's name it create_transaction_request

Nevermind me. Refunds and Voids are all under that resource.

rymcveigh’s picture

Just noting that I attempted to patch the latest release of this module with the latest commit on this branch and saw the same error tests are showing when attempting to checkout with test credentials.

1) Drupal\Tests\commerce_authnet\Kernel\AcceptJsPaymentMethodTest::testCreatePaymentMethodForAuthenticated
TypeError: Argument 2 passed to Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch() must be an instance of Symfony\Component\EventDispatcher\Event or null, string given, called in /var/www/html/modules/contrib/commerce_authnet/src/Plugin/Commerce/PaymentGateway/AcceptJs.php on line 813

The patch in #7 works great though.

lkacenja’s picture

Ran into a merge conflict with the previous patch, when attempting to update the module. I think those are now resolved.

vmarchuk’s picture

New patch compatible with version 8.x-1.7

nathaniel’s picture

Status: Needs review » Needs work

Symfony Event class deprecated 9.1.0... (broke while testing on a Drupal 10 site).

https://www.drupal.org/node/3159012

Before:
use Symfony\Component\EventDispatcher\Event;

After:
use Drupal\Component\EventDispatcher\Event;

nathaniel’s picture

Status: Needs work » Needs review
StatusFileSize
new8.63 KB
new8.26 KB

Tried to update the local patch based on the merge request / feedback and updated EventDispatcher\Event.

greggles’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for your help vmarchuck and for that QA and update for Drupal 10, Nathaniel!

Nudging this to RTBC. We've been using the various versions of it since 2019. Would be great to get a maintainer's feedback.

  • jsacksick committed b76048f1 on 8.x-1.x
    Issue #3089783 by mglaman, jsacksick, lkacenja, Nathaniel, zengenuity,...
jsacksick’s picture

Status: Reviewed & tested by the community » Fixed

Made several changes / fixes to the patch and committed it.

  • jsacksick committed fc5a1c52 on 8.x-1.x
    Issue #3089783 followup: Commit the missing event classes.
    
greggles’s picture

@jsacksick do you have an interdiff of your changes?

greggles’s picture

Also super appreciate you taking a look at this and committing it!

greggles’s picture

StatusFileSize
new40.04 KB

I think this is an interdiff of the changes from 16 up through #20.

Looks like some great improvements to me. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.