Page 1 of 1

Aimeos manual order creation (webhook Stripe)

Posted: 20 Dec 2017, 10:18
by Kevin
Hi all,

I'm using Aimeos for single products and subscriptions. So far, everything is working pretty fine. The last step to finalize the platform is to receive a webhook from Stripe when the subscription auto-renews.

When a subscription renews, I would like to add an order in the same way a normal order is placed via the backend. In other words, I want the order to appear in the order history of the client, I want the order to appear in my list of order to handle etc...

Someone has experience with this? Or someone can advise me on the best way to set this up?
I can directly input the database, but that would not be so clean. So I assume there are better options to build this.

Thanks for advising me on this one.

Regards,
Kevin

Re: Aimeos manual order creation (webhook Stripe)

Posted: 20 Dec 2017, 22:07
by aimeos
You only have to create an additional record in the mshop_order table, best using the order manager:

Code: Select all

$manager = \Aimeos\MShop\Factory::createManager( $context, 'order' );
$invoice = $manager->createItem();
$invoice->setBaseId( '<ID of mshop_order_base table with the related order>' );
$invoice->setType( \Aimeos\MShop\Order\Item\Base::TYPE_REPEAT );
$invoice->setDatePayment( date( 'Y-m-d H:i:s' ) );
$invoice->setPaymentStatus( \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED );
$manager->saveItem( $invoice );
You only need the Aimeos context for this.

Re: Aimeos manual order creation (webhook Stripe)

Posted: 22 Dec 2017, 16:11
by Kevin
Thank you for the feedback. Looking at your code I assume you attach an order to an already existing base item. That could work for me. But how do I use the code you provide into a standard Laravel controller?

I defined context like:

Code: Select all

$context = app( '\Aimeos\Shop\Base\Context' )->get( false );
But I receive following error "Locale object not available"...

Can you guide me on this please?

K.

Re: Aimeos manual order creation (webhook Stripe)

Posted: 24 Dec 2017, 18:11
by Travin
Hi Kevin!
Could you tell me how do you use Stripe subscriptions? Are you use ai-payments for this? Will you create a new order type at db and at Aimeos for subscriptions?

Re: Aimeos manual order creation (webhook Stripe)

Posted: 25 Dec 2017, 13:42
by aimeos
Kevin wrote: I defined context like:

Code: Select all

$context = app( '\Aimeos\Shop\Base\Context' )->get( false );
But I receive following error "Locale object not available"...
If you use false for the get() method, no locale object is added. Using no parameter will add the locale object:
https://aimeos.org/docs/Laravel/Extend_Aimeos

Re: Aimeos manual order creation (webhook Stripe)

Posted: 15 Feb 2018, 14:43
by Kevin
Hi!

Everything is working fine, except the mailing is send in English... Not in the language defined in the base item. How can I use the language that was defined in the base?

Code: Select all

$context = app( '\Aimeos\Shop\Base\Context' )->get(  );
		
		$manager = \Aimeos\MShop\Factory::createManager( $context, 'order' );
		$invoice = $manager->createItem();
		$invoice->setBaseId(101);
		$invoice->setType( \Aimeos\MShop\Order\Item\Base::TYPE_REPEAT );
		$invoice->setDatePayment( date( 'Y-m-d H:i:s' ) );
		$invoice->setPaymentStatus( \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED );
		$invoice->setDeliveryStatus(\Aimeos\MShop\Order\Item\Base::STAT_PROGRESS);
		$manager->saveItem( $invoice );

Re: Aimeos manual order creation (webhook Stripe)

Posted: 15 Feb 2018, 21:08
by aimeos
In the released versions, the language ID of the address is used for the e-mail language. In the dev-master branch a fall-back to the language of the order is now implemented