code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public function isActive() { return $this->times_left > 0; }
Check whether the RedeemedCoupon applies to the next Order. @return bool
isActive
php
laravel/cashier-mollie
src/Coupon/RedeemedCoupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/RedeemedCoupon.php
MIT
public static function addAmountForOwner(Model $owner, Money $amount) { return DB::transaction(function () use ($owner, $amount) { $current = static::whereOwner($owner)->whereCurrency($amount->getCurrency()->getCode())->first(); // if the owner already has a credit if ($current) { $current->increment('value', (int) $amount->getAmount()); return $current; } // if the owner has no credit yet return static::create([ 'owner_id' => $owner->getKey(), 'owner_type' => get_class($owner), 'currency' => $amount->getCurrency()->getCode(), 'value' => (int) $amount->getAmount(), ]); }); }
Add a credit amount for a specific owner. @param Model $owner @param \Money\Money $amount @return Model|\Laravel\Cashier\Credit\Credit
addAmountForOwner
php
laravel/cashier-mollie
src/Credit/Credit.php
https://github.com/laravel/cashier-mollie/blob/master/src/Credit/Credit.php
MIT
public static function maxOutForOwner(Model $owner, Money $amount) { return DB::transaction(function () use ($owner, $amount) { $credit = static::whereOwner($owner)->whereCurrency($amount->getCurrency()->getCode())->firstOrCreate([]); if ($credit->value == 0) { return money(0, $amount->getCurrency()->getCode()); } $use_credit = min([$credit->value, (int) $amount->getAmount()]); $credit->decrement('value', $use_credit); return money($use_credit, $amount->getCurrency()->getCode()); }); }
Use the max amount of owner's credit balance, striving to credit the target amount provided. @param Model $owner @param \Money\Money $amount The target amount @return \Money\Money The amount that was credited to the owner's balance.
maxOutForOwner
php
laravel/cashier-mollie
src/Credit/Credit.php
https://github.com/laravel/cashier-mollie/blob/master/src/Credit/Credit.php
MIT
public function money() { return money($this->value, $this->currency); }
Get the amount of credit as Money object. @return \Money\Money
money
php
laravel/cashier-mollie
src/Credit/Credit.php
https://github.com/laravel/cashier-mollie/blob/master/src/Credit/Credit.php
MIT
public function __construct($owner, string $oldMandateId) { $this->owner = $owner; $this->oldMandateId = $oldMandateId; }
ClearedMandate constructor. @param mixed $owner @param string $oldMandateId
__construct
php
laravel/cashier-mollie
src/Events/MandateClearedFromBillable.php
https://github.com/laravel/cashier-mollie/blob/master/src/Events/MandateClearedFromBillable.php
MIT
public function __construct(Model $owner, Payment $payment) { $this->owner = $owner; $this->payment = $payment; }
MandateUpdated constructor. @param \Illuminate\Database\Eloquent\Model $owner
__construct
php
laravel/cashier-mollie
src/Events/MandateUpdated.php
https://github.com/laravel/cashier-mollie/blob/master/src/Events/MandateUpdated.php
MIT
public function __construct($order) { $this->order = $order; }
Creates a new OrderCreated event. @param $order
__construct
php
laravel/cashier-mollie
src/Events/OrderCreated.php
https://github.com/laravel/cashier-mollie/blob/master/src/Events/OrderCreated.php
MIT
public function __construct($order) { $this->order = $order; }
Creates a new OrderInvoiceAvailable event. @param $order
__construct
php
laravel/cashier-mollie
src/Events/OrderInvoiceAvailable.php
https://github.com/laravel/cashier-mollie/blob/master/src/Events/OrderInvoiceAvailable.php
MIT
public function __construct($order) { $this->order = $order; }
Creates a new OrderPaymentFailed event. @param $order
__construct
php
laravel/cashier-mollie
src/Events/OrderPaymentFailed.php
https://github.com/laravel/cashier-mollie/blob/master/src/Events/OrderPaymentFailed.php
MIT
public function __construct($order) { $this->order = $order; }
Creates a new OrderPaymentFailed event. @param $order
__construct
php
laravel/cashier-mollie
src/Events/OrderPaymentFailedDueToInvalidMandate.php
https://github.com/laravel/cashier-mollie/blob/master/src/Events/OrderPaymentFailedDueToInvalidMandate.php
MIT
public function __construct($order) { $this->order = $order; }
Creates a new OrderPaymentPaid event. @param $order
__construct
php
laravel/cashier-mollie
src/Events/OrderPaymentPaid.php
https://github.com/laravel/cashier-mollie/blob/master/src/Events/OrderPaymentPaid.php
MIT
public function __construct(Order $order) { $this->order = $order; }
OrderProcessed constructor. @param \Laravel\Cashier\Order\Order $order
__construct
php
laravel/cashier-mollie
src/Events/OrderProcessed.php
https://github.com/laravel/cashier-mollie/blob/master/src/Events/OrderProcessed.php
MIT
public function __construct($subscription, $reason) { $this->subscription = $subscription; $this->reason = $reason; }
Creates a new SubscriptionCancelled event. @param Subscription $subscription @param string $reason
__construct
php
laravel/cashier-mollie
src/Events/SubscriptionCancelled.php
https://github.com/laravel/cashier-mollie/blob/master/src/Events/SubscriptionCancelled.php
MIT
public function __construct(string $message, int $code = 404, Throwable $previous = null) { parent::__construct($message, $code, $previous); }
CouponException constructor. @param string $message @param int $code @param \Throwable|null $previous
__construct
php
laravel/cashier-mollie
src/Exceptions/CouponException.php
https://github.com/laravel/cashier-mollie/blob/master/src/Exceptions/CouponException.php
MIT
public function __construct(string $message = 'Coupon not found', int $code = 404, Throwable $previous = null) { parent::__construct($message, $code, $previous); }
CouponNotFoundException constructor. @param string $message @param int $code @param Throwable|null $previous
__construct
php
laravel/cashier-mollie
src/Exceptions/CouponNotFoundException.php
https://github.com/laravel/cashier-mollie/blob/master/src/Exceptions/CouponNotFoundException.php
MIT
public function __construct(string $message = 'Currencies do not match', int $code = 404, Throwable $previous = null) { parent::__construct($message, $code, $previous); }
PlanNotFoundException constructor. @param string $message @param int $code @param Throwable|null $previous
__construct
php
laravel/cashier-mollie
src/Exceptions/CurrencyMismatchException.php
https://github.com/laravel/cashier-mollie/blob/master/src/Exceptions/CurrencyMismatchException.php
MIT
public function __construct(string $message = 'Invalid customer mandate', int $code = 404, Throwable $previous = null) { parent::__construct($message, $code, $previous); }
PlanNotFoundException constructor. @param string $message @param int $code @param Throwable|null $previous
__construct
php
laravel/cashier-mollie
src/Exceptions/InvalidMandateException.php
https://github.com/laravel/cashier-mollie/blob/master/src/Exceptions/InvalidMandateException.php
MIT
public function __construct(string $message = 'Plan not found', int $code = 404, Throwable $previous = null) { parent::__construct($message, $code, $previous); }
PlanNotFoundException constructor. @param string $message @param int $code @param Throwable|null $previous
__construct
php
laravel/cashier-mollie
src/Exceptions/PlanNotFoundException.php
https://github.com/laravel/cashier-mollie/blob/master/src/Exceptions/PlanNotFoundException.php
MIT
public function __construct(Model $owner, array $options = []) { $this->owner = $owner; $this->actions = new ActionCollection; $this->options = $options; $this->description = config('app.name', 'First payment'); $this->redirectUrl = url(config('cashier.first_payment.redirect_url', config('cashier.redirect_url'))); $this->webhookUrl = url(config('cashier.first_payment.webhook_url')); }
FirstPaymentBuilder constructor. @param \Illuminate\Database\Eloquent\Model $owner @param array $options Overrides the Mollie Payment payload
__construct
php
laravel/cashier-mollie
src/FirstPayment/FirstPaymentBuilder.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/FirstPaymentBuilder.php
MIT
public function inOrderTo(array $actions = []) { $this->actions = new ActionCollection($actions); return $this; }
Define actions to be executed once the payment has been paid. @param array $actions @return $this
inOrderTo
php
laravel/cashier-mollie
src/FirstPayment/FirstPaymentBuilder.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/FirstPaymentBuilder.php
MIT
public function getMolliePayload() { return array_filter(array_merge([ 'sequenceType' => SequenceType::SEQUENCETYPE_FIRST, 'method' => $this->method, 'customerId' => $this->owner->asMollieCustomer()->id, 'locale' => Cashier::getLocale($this->owner), 'description' => $this->description, 'amount' => money_to_mollie_array($this->actions->total()), 'webhookUrl' => $this->webhookUrl, 'redirectUrl' => $this->redirectUrl, 'metadata' => [ 'owner' => [ 'type' => get_class($this->owner), 'id' => $this->owner->getKey(), ], 'actions' => $this->actions->toMolliePayload(), ], ], $this->options)); }
Build the Mollie Payment Payload @return array
getMolliePayload
php
laravel/cashier-mollie
src/FirstPayment/FirstPaymentBuilder.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/FirstPaymentBuilder.php
MIT
public function setRedirectUrl(string $redirectUrl) { $this->redirectUrl = url($redirectUrl); return $this; }
Override the default Mollie redirectUrl. Takes an absolute or relative url. @param string $redirectUrl @return $this
setRedirectUrl
php
laravel/cashier-mollie
src/FirstPayment/FirstPaymentBuilder.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/FirstPaymentBuilder.php
MIT
public function setWebhookUrl(string $webhookUrl) { $this->webhookUrl = url($webhookUrl); return $this; }
Override the default Mollie webhookUrl. Takes an absolute or relative url. @param string $webhookUrl @return $this
setWebhookUrl
php
laravel/cashier-mollie
src/FirstPayment/FirstPaymentBuilder.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/FirstPaymentBuilder.php
MIT
public function getMolliePayment() { return $this->molliePayment; }
@return \Mollie\Api\Resources\Payment|null
getMolliePayment
php
laravel/cashier-mollie
src/FirstPayment/FirstPaymentBuilder.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/FirstPaymentBuilder.php
MIT
public function __construct(Payment $payment) { $this->payment = $payment; $this->owner = $this->extractOwner(); $this->actions = $this->extractActions(); }
FirstPaymentHandler constructor. @param \Mollie\Api\Resources\Payment $payment
__construct
php
laravel/cashier-mollie
src/FirstPayment/FirstPaymentHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/FirstPaymentHandler.php
MIT
public function execute() { $order = DB::transaction(function () { $this->owner->mollie_mandate_id = $this->payment->mandateId; $this->owner->save(); $orderItems = $this->executeActions(); return Order::createProcessedFromItems($orderItems, [ 'mollie_payment_id' => $this->payment->id, 'mollie_payment_status' => $this->payment->status, ]); }); event(new MandateUpdated($this->owner, $this->payment)); return $order; }
Execute all actions for the mandate payment and return the created Order. @return \Laravel\Cashier\Order\Order
execute
php
laravel/cashier-mollie
src/FirstPayment/FirstPaymentHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/FirstPaymentHandler.php
MIT
protected function extractOwner() { $ownerType = $this->payment->metadata->owner->type; $ownerID = $this->payment->metadata->owner->id; return $ownerType::findOrFail($ownerID); }
Fetch the owner model using the mandate payment metadata. @return \Illuminate\Database\Eloquent\Model
extractOwner
php
laravel/cashier-mollie
src/FirstPayment/FirstPaymentHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/FirstPaymentHandler.php
MIT
protected function extractActions() { $actions = new Collection((array) $this->payment->metadata->actions); return $actions->map(function ($actionMeta) { return $actionMeta->handler::createFromPayload( object_to_array_recursive($actionMeta), $this->owner ); }); }
Build the action objects from the payment metadata. @return \Illuminate\Support\Collection
extractActions
php
laravel/cashier-mollie
src/FirstPayment/FirstPaymentHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/FirstPaymentHandler.php
MIT
protected function executeActions() { $orderItems = new OrderItemCollection(); $this->actions->each(function (BaseAction $action) use (&$orderItems) { $orderItems = $orderItems->concat($action->execute()); }); return $orderItems; }
Execute the Actions and return a collection of the resulting OrderItems. These OrderItems are already paid for using the mandate payment. @return \Laravel\Cashier\Order\OrderItemCollection
executeActions
php
laravel/cashier-mollie
src/FirstPayment/FirstPaymentHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/FirstPaymentHandler.php
MIT
public function getOwner() { return $this->owner; }
Retrieve the owner object. @return \Illuminate\Database\Eloquent\Model
getOwner
php
laravel/cashier-mollie
src/FirstPayment/FirstPaymentHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/FirstPaymentHandler.php
MIT
public function getActions() { return $this->actions; }
Retrieve all Action objects. @return \Illuminate\Support\Collection
getActions
php
laravel/cashier-mollie
src/FirstPayment/FirstPaymentHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/FirstPaymentHandler.php
MIT
public function __construct(Model $owner, Money $subtotal, string $description) { parent::__construct($owner, $subtotal, $description); $this->taxPercentage = 0; // Adding balance is NOT taxed by default }
AddBalance constructor. @param \Illuminate\Database\Eloquent\Model $owner @param \Money\Money $subtotal @param string $description
__construct
php
laravel/cashier-mollie
src/FirstPayment/Actions/AddBalance.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/AddBalance.php
MIT
public function execute() { $this->owner->addCredit($this->getSubtotal()); return parent::execute(); }
Execute this action and return the created OrderItemCollection. @return \Laravel\Cashier\Order\OrderItemCollection
execute
php
laravel/cashier-mollie
src/FirstPayment/Actions/AddBalance.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/AddBalance.php
MIT
public function __construct(Model $owner, Money $subtotal, string $description, int $roundingMode = Money::ROUND_HALF_UP) { $this->owner = $owner; $this->taxPercentage = $this->owner->taxPercentage(); $this->unitPrice = $subtotal; $this->currency = $subtotal->getCurrency()->getCode(); $this->description = $description; $this->roundingMode = $roundingMode; }
AddGenericOrderItem constructor. @param \Illuminate\Database\Eloquent\Model $owner @param \Money\Money $subtotal @param string $description @param int $roundingMode
__construct
php
laravel/cashier-mollie
src/FirstPayment/Actions/AddGenericOrderItem.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/AddGenericOrderItem.php
MIT
public static function createFromPayload(array $payload, Model $owner) { $taxPercentage = isset($payload['taxPercentage']) ? $payload['taxPercentage'] : 0; return (new static( $owner, mollie_array_to_money($payload['subtotal']), $payload['description'] ))->withTaxPercentage($taxPercentage); }
@param array $payload @param \Illuminate\Database\Eloquent\Model $owner @return self
createFromPayload
php
laravel/cashier-mollie
src/FirstPayment/Actions/AddGenericOrderItem.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/AddGenericOrderItem.php
MIT
public function makeProcessedOrderItems() { return $this->owner->orderItems()->make([ 'description' => $this->getDescription(), 'currency' => $this->getCurrency(), 'process_at' => now(), 'unit_price' => $this->getSubtotal()->getAmount(), 'tax_percentage' => $this->getTaxPercentage(), 'quantity' => 1, ])->toCollection(); }
Prepare a stub of OrderItems processed with the payment. @return \Laravel\Cashier\Order\OrderItemCollection
makeProcessedOrderItems
php
laravel/cashier-mollie
src/FirstPayment/Actions/AddGenericOrderItem.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/AddGenericOrderItem.php
MIT
public function execute() { return tap($this->makeProcessedOrderItems(), function ($items) { $items->save(); }); }
Execute this action and return the created OrderItemCollection. @return \Laravel\Cashier\Order\OrderItemCollection
execute
php
laravel/cashier-mollie
src/FirstPayment/Actions/AddGenericOrderItem.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/AddGenericOrderItem.php
MIT
public function __construct(Model $owner, Coupon $coupon, OrderItemCollection $orderItems) { $this->owner = $owner; $this->coupon = $coupon; $this->orderItems = $this->coupon->handler()->getDiscountOrderItems($orderItems); }
ApplySubscriptionCouponToPayment constructor. @param \Illuminate\Database\Eloquent\Model $owner @param \Laravel\Cashier\Coupon\Coupon $coupon @param \Laravel\Cashier\Order\OrderItemCollection $orderItems
__construct
php
laravel/cashier-mollie
src/FirstPayment/Actions/ApplySubscriptionCouponToPayment.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/ApplySubscriptionCouponToPayment.php
MIT
protected function toMoney($value = 0) { return money($value, $this->getCurrency()); }
@param int $value @return \Money\Money
toMoney
php
laravel/cashier-mollie
src/FirstPayment/Actions/ApplySubscriptionCouponToPayment.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/ApplySubscriptionCouponToPayment.php
MIT
public function withTaxPercentage(float $percentage) { $this->taxPercentage = $percentage; return $this; }
@param float $percentage @example 21.5 @return $this
withTaxPercentage
php
laravel/cashier-mollie
src/FirstPayment/Actions/BaseAction.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/BaseAction.php
MIT
public function getTotal() { return $this->getSubtotal()->add($this->getTax()); }
The total after tax and discounts. @return \Money\Money
getTotal
php
laravel/cashier-mollie
src/FirstPayment/Actions/BaseAction.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/BaseAction.php
MIT
public static function createFromPayload(array $payload, Model $owner) { // }
Rebuild the Action from a payload. @param array $payload @param \Illuminate\Database\Eloquent\Model $owner
createFromPayload
php
laravel/cashier-mollie
src/FirstPayment/Actions/BaseNullAction.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/BaseNullAction.php
MIT
public function execute() { return new OrderItemCollection; }
Execute this action and return the created OrderItem or OrderItemCollection. @return \Laravel\Cashier\Order\OrderItem|\Laravel\Cashier\Order\OrderItemCollection
execute
php
laravel/cashier-mollie
src/FirstPayment/Actions/BaseNullAction.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/BaseNullAction.php
MIT
public function __construct(Model $owner, string $name, string $plan) { $this->owner = $owner; $this->taxPercentage = $this->owner->taxPercentage(); $this->name = $name; $this->plan = app(PlanRepository::class)::findOrFail($plan); $this->unitPrice = $this->plan->amount(); $this->description = $this->plan->description(); $this->currency = $this->unitPrice->getCurrency()->getCode(); $this->couponRepository = app()->make(CouponRepository::class); }
Create a new subscription builder instance. @param \Illuminate\Database\Eloquent\Model $owner @param string $name @param string $plan @throws \Laravel\Cashier\Exceptions\PlanNotFoundException
__construct
php
laravel/cashier-mollie
src/FirstPayment/Actions/StartSubscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/StartSubscription.php
MIT
public static function createFromPayload(array $payload, Model $owner) { $action = new static($owner, $payload['name'], $payload['plan']); // Already validated when preparing the first payment, so don't validate again $action->builder()->skipCouponValidation(); // The coupon will be handled manually by this action $action->builder()->skipCouponHandling(); if (isset($payload['taxPercentage'])) { $action->withTaxPercentage($payload['taxPercentage']); } if (isset($payload['trialUntil'])) { $action->trialUntil(Carbon::parse($payload['trialUntil'])); } if (isset($payload['trialDays'])) { $action->trialDays($payload['trialDays']); } if (isset($payload['skipTrial']) && $payload['skipTrial']) { $action->skipTrial(); } if (isset($payload['quantity'])) { $action->quantity($payload['quantity']); } if (isset($payload['coupon'])) { $action->withCoupon($payload['coupon']); } return $action; }
@param array $payload @param \Illuminate\Database\Eloquent\Model $owner @return static @throws \Exception
createFromPayload
php
laravel/cashier-mollie
src/FirstPayment/Actions/StartSubscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/StartSubscription.php
MIT
public function makeProcessedOrderItems() { return OrderItem::make($this->processedOrderItemData())->toCollection(); }
Prepare a stub of OrderItems processed with the payment. @return \Laravel\Cashier\Order\OrderItemCollection
makeProcessedOrderItems
php
laravel/cashier-mollie
src/FirstPayment/Actions/StartSubscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/StartSubscription.php
MIT
public function execute() { if (empty($this->nextPaymentAt) && ! $this->isTrial()) { $this->builder()->nextPaymentAt(Carbon::parse($this->plan->interval())); } // Create the subscription, scheduling the next payment $subscription = $this->builder()->create(); // Create an additional OrderItem for the already processed payment /** @var OrderItemCollection $processedItems */ $processedItems = $subscription->orderItems() ->create($this->processedOrderItemData()) ->toCollection(); if ($this->coupon) { $redeemedCoupon = RedeemedCoupon::record($this->coupon, $subscription); if (! $this->isTrial()) { $processedItems = $this->coupon->applyTo($redeemedCoupon, $processedItems); } } return $processedItems; }
Returns an OrderItemCollection ready for processing right away. Another OrderItem is scheduled for the next billing cycle. @return \Laravel\Cashier\Order\OrderItemCollection @throws \Laravel\Cashier\Exceptions\PlanNotFoundException @throws \Throwable
execute
php
laravel/cashier-mollie
src/FirstPayment/Actions/StartSubscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/StartSubscription.php
MIT
public function trialDays(int $trialDays) { $this->trialDays = $trialDays; $this->builder()->trialDays($trialDays); $this->unitPrice = money(0, $this->getCurrency()); return $this; }
Specify the number of days of the trial. @param int $trialDays @return $this @throws \Laravel\Cashier\Exceptions\PlanNotFoundException @throws \Throwable
trialDays
php
laravel/cashier-mollie
src/FirstPayment/Actions/StartSubscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/StartSubscription.php
MIT
public function trialUntil(Carbon $trialUntil) { $this->trialUntil = $trialUntil; $this->builder()->trialUntil($trialUntil); $this->unitPrice = money(0, $this->getCurrency()); return $this; }
Specify the ending date of the trial. @param Carbon $trialUntil @return $this
trialUntil
php
laravel/cashier-mollie
src/FirstPayment/Actions/StartSubscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/StartSubscription.php
MIT
public function skipTrial() { $this->skipTrial = true; $this->trialUntil = null; $this->builder()->skipTrial(); $this->unitPrice = $this->plan->amount(); return $this; }
Force the trial to end immediately. @return $this
skipTrial
php
laravel/cashier-mollie
src/FirstPayment/Actions/StartSubscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/StartSubscription.php
MIT
public function quantity(int $quantity) { throw_if($quantity < 1, new \LogicException('Subscription quantity must be at least 1.')); $this->quantity = $quantity; $this->builder()->quantity($quantity); return $this; }
Specify the quantity of the subscription. @param int $quantity @return $this @throws \Throwable|\LogicException
quantity
php
laravel/cashier-mollie
src/FirstPayment/Actions/StartSubscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/StartSubscription.php
MIT
public function coupon() { return $this->coupon; }
@return \Laravel\Cashier\Coupon\Coupon|null
coupon
php
laravel/cashier-mollie
src/FirstPayment/Actions/StartSubscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/StartSubscription.php
MIT
public function withCoupon(string $coupon) { $this->coupon = $this->couponRepository->findOrFail($coupon); $this->builder()->withCoupon($coupon); return $this; }
Specify and validate the coupon code. @param string $coupon @return $this @throws \Laravel\Cashier\Exceptions\CouponNotFoundException @throws \Throwable
withCoupon
php
laravel/cashier-mollie
src/FirstPayment/Actions/StartSubscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/StartSubscription.php
MIT
public function nextPaymentAt(Carbon $nextPaymentAt) { $this->nextPaymentAt = $nextPaymentAt; return $this; }
Override the default next payment date. @param \Carbon\Carbon $nextPaymentAt @return $this
nextPaymentAt
php
laravel/cashier-mollie
src/FirstPayment/Actions/StartSubscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/StartSubscription.php
MIT
public function builder() { if ($this->builder === null) { $this->builder = new MandatedSubscriptionBuilder( $this->owner, $this->name, $this->plan->name() ); } return $this->builder; }
Retrieve the subscription builder @return \Laravel\Cashier\SubscriptionBuilder\MandatedSubscriptionBuilder @throws \Throwable|\Laravel\Cashier\Exceptions\PlanNotFoundException
builder
php
laravel/cashier-mollie
src/FirstPayment/Actions/StartSubscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/FirstPayment/Actions/StartSubscription.php
MIT
function object_to_array_recursive($object) { if (empty($object)) { return null; } return json_decode(json_encode($object, JSON_FORCE_OBJECT), true); }
Recursively cast an object into an array. @param $object @return array|null
object_to_array_recursive
php
laravel/cashier-mollie
src/Helpers/helpers.php
https://github.com/laravel/cashier-mollie/blob/master/src/Helpers/helpers.php
MIT
function money(int $value, string $currency) { return new Money($value, new Currency($currency)); }
Create a Money object from a Mollie Amount array. @param int $value @param string $currency @return \Money\Money
money
php
laravel/cashier-mollie
src/Helpers/helpers.php
https://github.com/laravel/cashier-mollie/blob/master/src/Helpers/helpers.php
MIT
function decimal_to_money(string $value, string $currency) { $moneyParser = new DecimalMoneyParser(new ISOCurrencies()); return $moneyParser->parse($value, new Currency($currency)); }
Create a Money object from a decimal string / currency pair. @param string $value @param string $currency @return \Money\Money
decimal_to_money
php
laravel/cashier-mollie
src/Helpers/helpers.php
https://github.com/laravel/cashier-mollie/blob/master/src/Helpers/helpers.php
MIT
function mollie_array_to_money(array $array) { return decimal_to_money($array['value'], $array['currency']); }
Create a Money object from a Mollie Amount array. @param array $array @return \Money\Money
mollie_array_to_money
php
laravel/cashier-mollie
src/Helpers/helpers.php
https://github.com/laravel/cashier-mollie/blob/master/src/Helpers/helpers.php
MIT
function money_to_mollie_array(Money $money) { $moneyFormatter = new DecimalMoneyFormatter(new ISOCurrencies()); return [ 'currency' => $money->getCurrency()->getCode(), 'value' => $moneyFormatter->format($money), ]; }
Create a Mollie Amount array from a Money object. @param \Money\Money @return array $array
money_to_mollie_array
php
laravel/cashier-mollie
src/Helpers/helpers.php
https://github.com/laravel/cashier-mollie/blob/master/src/Helpers/helpers.php
MIT
function mollie_object_to_money(object $object) { return decimal_to_money($object->value, $object->currency); }
Create a Money object from a Mollie Amount object. @param object $object @return \Money\Money
mollie_object_to_money
php
laravel/cashier-mollie
src/Helpers/helpers.php
https://github.com/laravel/cashier-mollie/blob/master/src/Helpers/helpers.php
MIT
function money_to_decimal(Money $money) { return (new DecimalMoneyFormatter(new ISOCurrencies()))->format($money); }
Format the money as basic decimal @param \Money\Money $money @return string|bool
money_to_decimal
php
laravel/cashier-mollie
src/Helpers/helpers.php
https://github.com/laravel/cashier-mollie/blob/master/src/Helpers/helpers.php
MIT
public function getPaymentById($id) { try { return $this->getMolliePayment->execute($id); } catch (ApiException $e) { if (! config('app.debug')) { // Prevent leaking information return null; } throw $e; } }
Fetch a payment from Mollie using its ID. Returns null if the payment cannot be retrieved. @param $id @return \Mollie\Api\Resources\Payment|null @throws \Mollie\Api\Exceptions\ApiException
getPaymentById
php
laravel/cashier-mollie
src/Http/Controllers/BaseWebhookController.php
https://github.com/laravel/cashier-mollie/blob/master/src/Http/Controllers/BaseWebhookController.php
MIT
public function handleWebhook(Request $request) { $paymentId = $request->get('id'); // If a paid order already exists this webhook call is for a refund or chargeback $existingOrder = Order::findByPaymentId($paymentId); if ($existingOrder && $existingOrder->mollie_payment_status === PaymentStatus::STATUS_PAID) { // Do nothing. Refunds and chargebacks are not supported in cashier-mollie v1 return new Response(null, 200); } $payment = $this->getPaymentById($paymentId); if ($payment) { if ($payment->isPaid()) { $order = (new FirstPaymentHandler($payment))->execute(); Event::dispatch(new FirstPaymentPaid($payment, $order)); } elseif ($payment->isFailed()) { Event::dispatch(new FirstPaymentFailed($payment)); } } return new Response(null, 200); }
@param Request $request @return Response @throws \Mollie\Api\Exceptions\ApiException Only in debug mode
handleWebhook
php
laravel/cashier-mollie
src/Http/Controllers/FirstPaymentWebhookController.php
https://github.com/laravel/cashier-mollie/blob/master/src/Http/Controllers/FirstPaymentWebhookController.php
MIT
public function handleWebhook(Request $request) { $payment = $this->getPaymentById($request->get('id')); if ($payment) { $order = $this->getOrder($payment); if ($order && $order->mollie_payment_status !== $payment->status) { switch ($payment->status) { case PaymentStatus::STATUS_PAID: $order->handlePaymentPaid(); break; case PaymentStatus::STATUS_FAILED: $order->handlePaymentFailed(); break; default: break; } } } return new Response(null, 200); }
@param Request $request @return Response @throws \Mollie\Api\Exceptions\ApiException Only in debug mode
handleWebhook
php
laravel/cashier-mollie
src/Http/Controllers/WebhookController.php
https://github.com/laravel/cashier-mollie/blob/master/src/Http/Controllers/WebhookController.php
MIT
protected function getOrder(Payment $payment) { $order = Order::findByPaymentId($payment->id); if (! $order && isset($payment->metadata, $payment->metadata->temporary_mollie_payment_id)) { $order = Order::findByPaymentId($payment->metadata->temporary_mollie_payment_id); if ($order) { // Store the definite payment id. $order->update(['mollie_payment_id' => $payment->id]); } } return $order; }
@param \Mollie\Api\Resources\Payment $payment @return \Laravel\Cashier\Order\Order|null
getOrder
php
laravel/cashier-mollie
src/Http/Controllers/WebhookController.php
https://github.com/laravel/cashier-mollie/blob/master/src/Http/Controllers/WebhookController.php
MIT
public function __construct( Model $owner, string $description, Money $amount, string $webhookUrl, array $overrides = [] ) { $this->owner = $owner; $this->description = $description; $this->amount = $amount; $this->webhookUrl = $webhookUrl; $this->overrides = $overrides; }
MandatedPaymentBuilder constructor. @param \Illuminate\Database\Eloquent\Model $owner @param string $description @param \Money\Money $amount @param string $webhookUrl @param array $overrides
__construct
php
laravel/cashier-mollie
src/MandatedPayment/MandatedPaymentBuilder.php
https://github.com/laravel/cashier-mollie/blob/master/src/MandatedPayment/MandatedPaymentBuilder.php
MIT
public function create(array $overrides = []) { /** @var CreateMolliePayment $createMolliePayment */ $createMolliePayment = app()->make(CreateMolliePayment::class); return $createMolliePayment->execute($this->getPayload($overrides)); }
@param array $overrides @return \Mollie\Api\Resources\Payment
create
php
laravel/cashier-mollie
src/MandatedPayment/MandatedPaymentBuilder.php
https://github.com/laravel/cashier-mollie/blob/master/src/MandatedPayment/MandatedPaymentBuilder.php
MIT
protected function toMoney($value = 0) { return money(round($value), $this->getCurrency()); }
@param int $value @return \Money\Money
toMoney
php
laravel/cashier-mollie
src/Order/ConvertsToMoney.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/ConvertsToMoney.php
MIT
public function __construct($currency, $id = null, $date = null) { $this->currency = $currency; $this->id = $id; $this->date = $date ?: Carbon::now(); $this->items = new Collection; $this->receiverAddress = new Collection; $this->extraInformation = new Collection; }
Invoice constructor. @param string $currency @param string|null $id @param Carbon|null $date
__construct
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function setDate(Carbon $date) { $this->date = $date; return $this; }
@param \Carbon\Carbon $date @return $this
setDate
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function addItem(InvoicableItem $item) { $this->items->push($item); return $this; }
@param \Laravel\Cashier\Order\Contracts\InvoicableItem $item @return $this
addItem
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function addItems(Collection $items) { $this->items = $this->items->concat($items); return $this; }
Add multiple InvoicableItems @param \Illuminate\Support\Collection $items @return $this
addItems
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function items() { return $this->items; }
Returns a collection of invoice items @return \Illuminate\Support\Collection
items
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function subtotal() { return $this->formatAmount($this->rawSubtotal()); }
The formatted sum of all items' subtotals @return string
subtotal
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function rawSubtotal() { $subtotal = money(0, $this->currency); $this->items->each(function (InvoicableItem $item) use (&$subtotal) { $subtotal = $subtotal->add($item->getSubtotal()); }); return $subtotal; }
The raw sum of all items' subtotals @return \Money\Money
rawSubtotal
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function total() { return $this->formatAmount($this->rawTotal()); }
The formatted sum of all items' totals. @return string
total
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function rawTotal() { $subtotal = money(0, $this->currency); $this->items->each(function (InvoicableItem $item) use (&$subtotal) { $subtotal = $subtotal->add($item->getTotal()); }); return $subtotal; }
The raw sum of all items' totals. @return \Money\Money
rawTotal
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function totalDue() { return $this->formatAmount($this->rawTotalDue()); }
The formatted sum of all items' totals minus the balance used. @return string
totalDue
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function rawTotalDue() { return $this->rawTotal()->subtract($this->rawUsedBalance()); }
The raw sum of all items' totals minus the balance used. @return \Money\Money
rawTotalDue
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function taxDetails() { $percentages = $this->items->pluck('tax_percentage')->unique()->sort(); $total_per_percentage = function ($percentage) { $items = $this->items->where('tax_percentage', $percentage); $raw_over_subtotal = $items->sum(function (InvoicableItem $item) { return $item->getSubtotal()->getAmount(); }); $raw_total = $items->sum(function (InvoicableItem $item) { return $item->getTax()->getAmount(); }); return [ 'tax_percentage' => (float) $percentage, 'raw_over_subtotal' => $raw_over_subtotal, 'over_subtotal' => $this->formatAmount(money($raw_over_subtotal, $this->currency)), 'raw_total' => $raw_total, 'total' => $this->formatAmount(money($raw_total, $this->currency)), ]; }; return $percentages->map($total_per_percentage)->values(); }
Get the tax totals summed up per tax percentage. @return \Illuminate\Support\Collection
taxDetails
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function receiverAddress($separator = null) { return $this->optionallyImplode($this->receiverAddress, $separator); }
Get the receiver address. By default a collection of lines (strings) is returned. If you provide separator, an imploded string is returned. @param null $separator @return \Illuminate\Support\Collection|string
receiverAddress
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function setReceiverAddress(array $lines) { $this->receiverAddress = new Collection($lines); return $this; }
Set the receiver address using an array of strings. @param array $lines @return $this
setReceiverAddress
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function startingBalance() { return $this->formatAmount($this->rawStartingBalance()); }
The formatted starting balance. @return string
startingBalance
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function rawStartingBalance() { return $this->startingBalance ?: money(0, $this->currency); }
The raw starting balance. @return \Money\Money|null
rawStartingBalance
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function setStartingBalance(Money $amount) { $this->startingBalance = $amount; return $this; }
@param \Money\Money $amount @return $this
setStartingBalance
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function usedBalance() { return $this->formatAmount($this->rawUsedBalance()); }
The formatted used balance. @return string
usedBalance
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function rawUsedBalance() { return $this->usedBalance ?: money(0, $this->currency); }
The raw used balance. @return \Money\Money|null
rawUsedBalance
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function setUsedBalance(Money $amount) { $this->usedBalance = $amount; return $this; }
@param \Money\Money $amount @return $this
setUsedBalance
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function completedBalance() { return $this->formatAmount($this->rawCompletedBalance()); }
The formatted balance after processing this invoice. @return string
completedBalance
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function rawCompletedBalance() { return $this->completedBalance ?: money(0, $this->currency); }
The formatted balance after processing this invoice. @return \Money\Money|null
rawCompletedBalance
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function setCompletedBalance(Money $amount) { $this->completedBalance = $amount; return $this; }
@param \Money\Money $amount @return $this
setCompletedBalance
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function extraInformation($separator = null) { return $this->optionallyImplode($this->extraInformation, $separator); }
Get the invoice's extra information. By default a collection of lines (strings) is returned. If you provide separator, an imploded string is returned. @param null $separator @return \Illuminate\Support\Collection|string
extraInformation
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function setExtraInformation(array $lines) { $this->extraInformation = new Collection($lines); return $this; }
Set the extra information. Useful for adding a note. @param array $lines @return $this
setExtraInformation
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function view(array $data = [], string $view = self::DEFAULT_VIEW) { return View::make($view, array_merge($data, [ 'invoice' => $this, ])); }
Get the View instance for the invoice. @param array $data @param string $view @return \Illuminate\Contracts\View\View
view
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function pdf(array $data = [], string $view = self::DEFAULT_VIEW, Options $options = null) { if (! defined('DOMPDF_ENABLE_AUTOLOAD')) { define('DOMPDF_ENABLE_AUTOLOAD', false); } $dompdf = new Dompdf($options); $dompdf->loadHtml($this->view($data, $view)->render()); $dompdf->render(); return $dompdf->output(); }
Capture the invoice as a PDF and return the raw bytes. @param array $data @param string $view @param \Dompdf\Options $options @return string
pdf
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public function download(array $data = [], string $view = self::DEFAULT_VIEW, Options $options = null) { $filename = implode('_', [ $this->id, Str::snake(config('app.name', '')), ]) . '.pdf'; return new Response($this->pdf($data, $view, $options), 200, [ 'Content-Description' => 'File Transfer', 'Content-Disposition' => 'attachment; filename="'.$filename.'"', 'Content-Transfer-Encoding' => 'binary', 'Content-Type' => 'application/pdf', ]); }
Create an invoice download response. @param null|array $data @param string $view @param \Dompdf\Options $options @return \Symfony\Component\HttpFoundation\Response
download
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
private function optionallyImplode(Collection $collection, $separator) { if ($separator === null) { return $collection; } return $collection->implode($separator); }
Helper method. By default a collection of lines (strings) is returned. If a separator is provided an imploded string is returned. @param \Illuminate\Support\Collection $collection @param $separator @return \Illuminate\Support\Collection|string
optionallyImplode
php
laravel/cashier-mollie
src/Order/Invoice.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Invoice.php
MIT
public static function createFromItems(OrderItemCollection $items, $overrides = [], $process_items = true) { return DB::transaction(function () use ($items, $overrides, $process_items) { if ($process_items) { $items = $items->preprocess(); } if ($items->currencies()->count() > 1) { throw new LogicException('Creating an order requires items to have a single currency.'); } if ($items->owners()->count() > 1) { throw new LogicException('Creating an order requires items to have a single owner.'); } $currency = $items->first()->currency; $owner = $items->first()->owner; $total = $items->sum('total'); $order = static::create(array_merge([ 'owner_id' => $owner->getKey(), 'owner_type' => get_class($owner), 'number' => static::numberGenerator()->generate(), 'currency' => $currency, 'subtotal' => $items->sum('subtotal'), 'tax' => $items->sum('tax'), 'total' => $total, 'total_due' => $total, ], $overrides)); $items->each(function (OrderItem $item) use ($order, $process_items) { $item->update(['order_id' => $order->id]); if ($process_items) { $item->process(); } }); Event::dispatch(new OrderCreated($order)); return $order; }); }
Creates an order from a collection of OrderItems @param \Laravel\Cashier\Order\OrderItemCollection $items @param array $overrides @param bool $process_items @return Order
createFromItems
php
laravel/cashier-mollie
src/Order/Order.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php
MIT
public static function createProcessedFromItems(OrderItemCollection $items, $overrides = []) { $order = static::createFromItems( $items, array_merge([ 'processed_at' => now(), ], $overrides), false ); Event::dispatch(new OrderProcessed($order)); return $order; }
Creates a processed order from a collection of OrderItems @param \Laravel\Cashier\Order\OrderItemCollection $items @param array $overrides @return Order
createProcessedFromItems
php
laravel/cashier-mollie
src/Order/Order.php
https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php
MIT