1

I'm trying to only allow the "checkmo" payment method to be used when an order is placed through the API, but not available for a customer on the frontend to choose.

Ive tried creating a plugin that essentially does the following -

$area_code  = $this->app_state->getAreaCode();
    if($area_code != \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE){
        if($subject->getCode() == 'checkmo') {
            return false;
        }

This blocks the payment method from the frontend fine, but won't allow it to be used when the API looks at available payment methods. I'm guessing this is because the API is considered frontend.

Is there any way around this, or can another payment method be created where only API orders can access?

1

I'm guessing this is because the API is considered frontend.

That's not correct, but close. The frontend uses the API a lot in the checkout and that's the case here. Unfortunately you can't use the area-code to solve this problem.

Your best bet is excluding the payment method from being rendered in the template.

  • Makes sense I suppose. Where would be the best place to stop a certain payment method rendering? Would I need to hook into the javascipt that goes and fetches the available payment methods? – BigDaddyL May 8 at 14:41
  • In the payment template, look at the foreach payment method PHP loop, check if the payment method code is found. If found continue so that it skips it – elfling May 8 at 14:46
  • @elfling thanks for that. I've looked at the following code which I think does it - <div if="isPaymentMethodsAvailable()" class="payment-group__list"> <each args="data: getRegion($group().displayArea), as: 'method'" render="" /> </div> But i can't seem to work out how to manipulate this properly. – BigDaddyL May 16 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.