Questions regarding implementing PlanContract
mrjandejong opened this issue · 2 comments
mrjandejong commented
I have some questions regrading implementing the Laravel\Cashier\Plan\Contracts\Plan
:
- Under which circumstances does cashier-mollie use the
firstPaymentAmount()
?
Even though I have set thefirst_payment_amount
to 1 cent it still starts with the full month price. Fortunately this is what I want to happen anyway, but I would like to know why it actually doesn't use thefirst_payment_amount
- How to implement
orderItemPreprocessors()
?
I current justreturn new OrderItemPreprocessorCollection;
. But I would just like to use the defaults as described in the config files... Will it still useProcessCoupons
etc. like this, or nah?
This is my model file sofar:
<?php
namespace App\Models;
use Money\Money;
use Money\Currency;
use Illuminate\Database\Eloquent\Model;
use Laravel\Cashier\Plan\Contracts\Plan as PlanContract;
use Laravel\Cashier\Order\OrderItemPreprocessorCollection;
class Plan extends Model implements PlanContract
{
protected $fillable = [
'name', 'amount', 'interval', 'description', 'currency','first_payment_description','first_payment_amount'
];
/**
* @return \Money\Money
*/
public function amount() {
$currency = new Currency($this->attributes['currency']);
return new Money($this->attributes['amount'], $currency);
}
/**
* @param \Money\Money $amount
* @return Plan
*/
public function setAmount(Money $amount)
{
$this->attributes['currency'] = $amount->getCurrency();
$this->attributes['amount'] = $amount->getAmount();
return $this;
}
/**
* @return string
*/
public function description()
{
return $this->attributes['description'];
}
/**
* @return string
*/
public function interval()
{
return $this->attributes['interval'];
}
/**
* @return string
*/
public function name()
{
return $this->attributes['name'];
}
/**
* The amount the customer is charged for a mandate payment.
*
* @return \Money\Money
*/
public function firstPaymentAmount()
{
$currency = new Currency($this->attributes['first_payment_currency']);
return new Money($this->attributes['first_payment_amount'], $currency);
}
/**
* @param \Money\Money $firstPaymentAmount
* @return Plan
*/
public function setFirstPaymentAmount(Money $firstPaymentAmount)
{
$this->attributes['first_payment_currency'] = $firstPaymentAmount->getCurrency();
$this->attributes['first_payment_amount'] = $firstPaymentAmount->getAmount();
return $this;
}
/**
* @return string
*/
public function firstPaymentMethod()
{
return config('cashier.first_payment.method');
}
/**
* @param string $firstPaymentMethod
* @return Plan
*/
public function setFirstPaymentMethod(?string $firstPaymentMethod)
{
throw new Exception('Table is lacking column to persist this value');
}
/**
* The description for the mandate payment order item.
*
* @return string
*/
public function firstPaymentDescription()
{
return $this->attributes['first_payment_description'];
}
/**
* @param string $firstPaymentDescription
* @return Plan
*/
public function setFirstPaymentDescription(string $firstPaymentDescription)
{
$this->attributes['first_payment_description'] = $firstPaymentDescription;
return $this;
}
/**
* @return string
*/
public function firstPaymentRedirectUrl()
{
return config('cashier.first_payment.redirect_url');
}
/**
* @param string $redirectUrl
* @return Plan
*/
public function setFirstPaymentRedirectUrl(string $redirectUrl)
{
throw new Exception('Table is lacking column to persist this value');
}
/**
* @return string
*/
public function firstPaymentWebhookUrl()
{
return config('cashier.first_payment.webhook_url');
}
/**
* @param string $webhookUrl
* @return Plan
*/
public function setFirstPaymentWebhookUrl(string $webhookUrl)
{
throw new Exception('Table is lacking column to persist this value');
}
/**
* @return \Laravel\Cashier\Order\OrderItemPreprocessorCollection
*/
public function orderItemPreprocessors()
{
return new OrderItemPreprocessorCollection;
}
/**
* @param \Laravel\Cashier\Order\OrderItemPreprocessorCollection $preprocessors
* @return \Laravel\Cashier\Plan\Contracts\Plan
*/
public function setOrderItemPreprocessors(OrderItemPreprocessorCollection $preprocessors)
{
$this->orderItemPreprocessors = $preprocessors;
return $this;
}
}
sandervanhooft commented
The first payment amount is used when the first payment (mandate payment) is not a normal subscription payment, i.e. when starting with a trial.
sandervanhooft commented
If you want to use the default preprocessors you should return these from the orderItemPreprocessors
method.