Score:-3

Change workflow state with particular payment method

jp flag
Tak

Right now i have a payment method called "Transferência Bancária" and I need it to change to the workflow state "Awaiting Transferencia" automatically when that payment method is selected.

Is it possible to do programmatically?

I'm stuck at: $order = $event->getEntity(); if(($order->getPaymentGateway()) == ('transferencia')) { $order->set('state', 'aguardando_transferencia'); }

on my /modules/workflowtkn/src/EventSubscriber/WorkflowTknProcessSubscriber.php

Error: Call to undefined method Drupal\commerce_order\Entity\Order::getPaymentGateway()

EDIT: I'm having troubles calling the function "getPaymentGateway()" because is in another module, can somebody help, please :) It has to be corresponded to the order.

I've tried $gateway = \Drupal::service('plugin.manager.commerce_payment_method_type'); but it says can't convert to string... This:

$payment = $order->get('payment_gateway')->first()->entity

Gives me:

Warning: htmlspecialchars() expects parameter 1 to be string, object given in Drupal\Component\Utility\Html::escape() .

I've looked at How do I get information about the payment method from the order object programmatically? but can't figure it out.

I guess i'm failing to convert to string?

EDIT: When I use json_encode: json_encode($order->get('payment_gateway')->first()->entity) it only returns "{}"

cn flag
At a minimum, you need to read the docs yourself before asking here. Asking for a link to the docs is off-topic for this site.
Tak avatar
jp flag
Tak
I asked for the docs because i didn't find one for my specific issue, if there is one.
cn flag
Welcome to Drupal Answers :) As mentioned asking for links is off topic here, this is a Q+A site so we need the question and answer to be here, not somewhere else, or the site stagnates when the external links go down. For the remaining question the answer is definitely "yes", but again, for this format you'll need to be more specific about the problem. Add details of what you've tried, error messages, and so on. If you haven't started yet, or haven't found the commerce documentation, you're probably a bit early on to ask a question here just yet
Tak avatar
jp flag
Tak
Thank you Clive. I've been researching this for the last couple of days, but since there is no support for my issue im realy strugling. As for more information, I created a module for a custom workflow and different states. I have a manual payment method that gives the IBAN of my business for the client to transfer the money, has soon as he/her chooses it, my colegues want the order to pass to a chosen state, which is "Awaiting Transfer" in my custom workflow.
Score:1
jp flag
Tak

After much head bashing and pure luck i found out the solution. In order.php:

function getPay()
{
    return $this->get('payment_gateway')->entity->get('label');
}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.