If checkout is allowed for anonymous users, the AuthorizeNet::doCreatePaymentMethod() fails because the user email address is empty.
protected function doCreatePaymentMethod(PaymentMethodInterface $payment_method, array $payment_details) {
...
if ($owner->isAuthenticated()) {
$profile = new Profile([
// @todo how to allow altering.
'merchantCustomerId' => $owner->id(),
'email' => $owner->getEmail(),
]);
}
else {
$profile = new Profile([
// @todo how to allow altering.
'merchantCustomerId' => $owner->id() . '_' . REQUEST_TIME,
'email' => $owner->getEmail(), // <<<<<<<<<<<<<<<< This is empty for anonymous users
]);
...
}
AuthNet doesn't allow for an empty email to be passed in. If this property is removed (I just commented it out), AuthNet does accept it. A quick fix is to remove email from the anonymous users. A better long term fix would be to pull their email info in from their billing profile.
Comments
Comment #2
mglamanHm, the billing profile does not have an email. And the order's email should be set from the account information pane, where they have to enter an email address. So instead of $owner we need to do $order
Comment #3
mglamanWe don't have access to the order in that method. So just omitting.
Comment #4
mglamanHm, but from the API page http://developer.authorize.net/api/reference/#customer-profiles-create-c...
That patch is a quickfix. The method should probably be revisited. It's borrowed from the first gateway we wrote, Braintree, which supported tokenization much more easily.
Comment #5
mglamanThe module just cannot support anonymous checkout at the moment. When I applied this fix, I then had errors with the customer profile ID.
It is null here, leading to
Since the 2.x architecture is built around tokenized payment methods.. I don't think there is anyway to solve this until we implement Accept.js.
Comment #6
mglamanComment #7
bojanz commentedLooks like we found a Commerce API bug. Opened #2895335: Payment gateway's createPaymentMethod() method doesn't have access to the customer email on anonymous orders.
Comment #8
adrian83 commentedSo is this blocked by the lack of Accept.js
Comment #9
bradjones1And to clarify, using Accept.js means this bug doesn't apply.
Comment #10
czigor commentedUsing the access.js patch in #2813401-15: Use Accept.js to ease PCI requirements. I can make anonymous checkouts.
Comment #11
mglamanWe need to add a test for this.
Comment #12
nikathoneA fix for this at http://cgit.drupalcode.org/commerce_authnet/tree/src/Plugin/Commerce/Pay... is already implemented. I guess we should find a better way of collecting the anonymous user email than the one in http://cgit.drupalcode.org/commerce_authnet/tree/src/PluginForm/Authoriz... then close this issue. Switched it to need review for the latest beta not the patch.
Comment #13
mglamanOkay, so this is _working_ but is fragile and really needs a core API improvement (still)
Comment #14
mglamanI'm marking this fixed. It's working, albeit we need a core API improvement to get order email for payment method.
Comment #15
mglamanFixing credits. Credits all around. Credits for debugging this thing.,