The following code handles the duplicate payment profile response

        // Handle duplicate.
        if ($response->getMessages()[0]->getCode() == 'E00039') {
          $result = array_filter(explode(' ', $response->getMessages()[0]->getText()), 'is_numeric');
          $customer_id = reset($result);

          $payment_profile = $this->buildCustomerPaymentProfile($payment_method, $payment_details, $customer_id);
          $request = new CreateCustomerPaymentProfileRequest($this->authnetConfiguration, $this->httpClient);
          $request->setCustomerProfileId($customer_id);
          $request->setPaymentProfile($payment_profile);
          $response = $request->execute();

          if ($response->getResultCode() != 'Ok') {
            throw new InvalidResponseException("Unable to create payment profile for existing customer");
          }

          $payment_profile_id = $response->customerPaymentProfileId;
        }

However this means duplicate cards will show up in Drupal. This needs to look up if the remote ID is already saved as a payment method for the user and then return it. This will require working \Drupal\commerce_authnet\Plugin\Commerce\PaymentGateway\AuthorizeNet::doCreatePaymentMethod a bit.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Issue tags: +#fldc18
mglaman’s picture

Assigned: Unassigned » mglaman

Sorting this out.

mglaman’s picture

Status: Active » Needs review
Issue tags: -#fldc18
FileSize
2.77 KB

Here is a list of what deems things as a duplicate: https://developer.authorize.net/api/reference/features/customer_profiles...

This test forces the User to always have `uid` 10 and a matching email. This will fail.

Status: Needs review » Needs work

The last submitted patch, 4: 2832501-4.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mglaman’s picture

The error being returned is actually

stdClass Object
(
    [refId] => ref1525108998
    [messages] => stdClass Object
        (
            [resultCode] => Error
            [message] => stdClass Object
                (
                    [code] => E00114
                    [text] => Invalid OTS Token.
                )

        )

)

I think the problem is that the OTS for Accept.js is being consumed, then invalidated on the "hey there is a duplicate" error. So it seems like we need to split out customer profile creation and payment profile creation from one call to two, always.

mglaman’s picture

Status: Needs work » Needs review
FileSize
6.24 KB

Need to review this. Tests should pass, now!

Status: Needs review » Needs work

The last submitted patch, 7: 2832501-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mglaman’s picture

Whoops. Forgot I needed to tag rc2 of the SDK.

mglaman’s picture

Status: Needs work » Needs review

  • mglaman committed 9bc7c09 on 8.x-1.x
    Issue #2832501 by mglaman: Duplicate payment profile code should lookup...
mglaman’s picture

Status: Needs review » Fixed

Fixed!

Status: Fixed » Closed (fixed)

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