How to transfer back money by PayPalExpress (not backend)?

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
claude27
Posts: 15
Joined: 25 Jul 2024, 11:24

How to transfer back money by PayPalExpress (not backend)?

Post by claude27 » 22 Jan 2025, 21:38

Hi,

is performing refunds still only possible in the admin backend (see attached screenshot, transaction view) or is there in the meantime a way to process it via a php controller?

I've created an user restricted area where frontend users can create and edit events which are synchronised with the aimeos products. Now they should be able to cancel orders.

I managed to change the status of an order for the refund and an email (same as from the backend) is sent to the customer which informs him about the refund, but I didn't yet manage to automatically transfer money back to his paypal account like it can be done in the backend (see attached screenshot).

At the moment I'm testing with the paypal sandbox.

This is my code at the moment:

Code: Select all

/**
     * Action refund
     * @param integer id
     *
     * @return void
     */
    public function cancelProductAction( $id ): void {
        $config = Base::config((array) $this->settings);
        $context = \Aimeos\Aimeos\Base::context($config);

        $orderManager = MShop::create($context, 'order');
        $order = $orderManager->get( $id );

        $status = \Aimeos\MShop\Order\Item\Base::PAY_REFUND;
        $order->setStatusPayment( $status );
        $orderManager->save( $order );
    }
What's the best way to start the process for the money transaction?

Aimeos: 24.4.2
TYPO3: 12.4.25

Thank you for any hint!
Attachments
screenshot-www.aimeos.ddev.site-2025.01.22-22_18_20.png
screenshot-www.aimeos.ddev.site-2025.01.22-22_18_20.png (30.58 KiB) Viewed 506 times

User avatar
aimeos
Administrator
Posts: 8447
Joined: 01 Jan 1970, 00:00

Re: How to transfer back money by PayPalExpress (not backend)?

Post by aimeos » 23 Jan 2025, 09:35

Here you can see the API calls for a refund:
https://github.com/aimeos/ai-admin-jqad ... #L221-L255
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

claude27
Posts: 15
Joined: 25 Jul 2024, 11:24

Re: How to transfer back money by PayPalExpress (not backend)?

Post by claude27 » 23 Jan 2025, 13:59

Thank you very much!
It works now :-)

The only things now, which also happens when refunding by the backend:
The customer is receiving again the original invoice in the email and in the attached pdf and not something like a credit note (in german: Gutschrift, e.g. with negative values). Have I perhaps overlooked something?

And the email subject is still the same. But I think I can change this easily in the template.

claude27
Posts: 15
Joined: 25 Jul 2024, 11:24

Re: How to transfer back money by PayPalExpress (not backend)?

Post by claude27 » 23 Jan 2025, 17:47

PS: I have also now noticed that partial refunds do not work. PayPal Express always transfers the entire amount back. Is this perhaps a bug? (I have to ask my client if cancellation fees are needed)

User avatar
aimeos
Administrator
Posts: 8447
Joined: 01 Jan 1970, 00:00

Re: How to transfer back money by PayPalExpress (not backend)?

Post by aimeos » 24 Jan 2025, 13:33

claude27 wrote: 23 Jan 2025, 13:59 The customer is receiving again the original invoice in the email and in the attached pdf and not something like a credit note (in german: Gutschrift, e.g. with negative values). Have I perhaps overlooked something?

And the email subject is still the same. But I think I can change this easily in the template.
The order/email/payment job controller currently sends that e-mail but it's not suitable for credit notes. You can remove the refund status by setting the "controller/jobs/order/email/payment/status" configuration to [4,5,6] only:
https://aimeos.org/docs/2024.x/config/c ... /#status_1

Afterwards, you need to copy the order/email/payment job controller and it's templates and rewrite them for a credit note.
We would love if you can create a PR with your changes so we can integrate it into the core and offer it in the next release :-)
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply