Open zqstack opened 4 years ago
First of all, it would help a lot if you remove all of your logs from the code. Second, I think you don't need to implement PreprocessesOrderItems
. That's up to cashier. You just need to extend BaseOrderItemPreprocessor
and write the logic for handle()
to modify your OrderItems. And finally, to solve your isssue. Preprocessors are not invoked when creating a new subscription, as you can see in the create()
method of a MandatedSubscriptionBuilder:
/**
* Create a new Cashier subscription.
*
* @return Subscription
* \Laravel\Cashier\Exceptions\CouponException
* @throws \Laravel\Cashier\Exceptions\InvalidMandateException
*/
public function create()
{
$this->owner->guardMollieMandate();
$now = now();
return DB::transaction(function () use ($now) {
$subscription = $this->makeSubscription($now);
$subscription->save();
if($this->coupon) {
if($this->validateCoupon) {
$this->coupon->validateFor($subscription);
if($this->handleCoupon) {
$this->coupon->redeemFor($subscription);
}
}
}
$subscription->scheduleNewOrderItemAt($this->nextPaymentAt);
$subscription->save();
$this->owner->cancelGenericTrial();
return $subscription;
});
}
The preprocessors are only invoked when processing a subscription right before a mollie payment is created. You could therefore start a subscription with a price of your choice and always change the unit_price
whenever such a subscription would be billed using the preprocessor you've created.
I have a similar situation and thanks @lexdewilligen you for the tips, I have the PaymentPreprocessors working now.
One question remains. How can I change the price of the firstPayment?
I have a custom plan in my cashier_plans.php
but the price is dynamic and is per client different. So i would like to change the amount of the firstPayment per user.
I've found some more information in this thread https://github.com/laravel/cashier-mollie/issues/177
But i cannot find out how to use the FirstPaymentBuilder
manually in a controller.
Dear Developer,
Do you know why my preprocessor for variable prices is not working correctly?
It seems to work for swapping plans, but for new subscriptions, it keeps asking for the original price. Am I missing something?
Here is my code:
cashier_plans.php:
MyPreprocessor.php:
Thank you for your help!
zqstack