Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#9 | 2832501-9.patch | 6.67 KB | mglaman |
| |||
#7 | 2832501-7.patch | 6.24 KB | mglaman |
#4 | 2832501-4.patch | 2.77 KB | mglaman |
Comments
Comment #2
mglamanComment #3
mglamanSorting this out.
Comment #4
mglamanHere 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.
Comment #6
mglamanThe error being returned is actually
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.
Comment #7
mglamanNeed to review this. Tests should pass, now!
Comment #9
mglamanWhoops. Forgot I needed to tag rc2 of the SDK.
Comment #10
mglamanComment #12
mglamanFixed!