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 validateMollieMandate() { if ($this->validMollieMandate()) { return true; } $this->clearMollieMandate(); return false; }
Checks whether the Mollie mandate is still valid. If not, clears it. @return bool
validateMollieMandate
php
laravel/cashier-mollie
src/Billable.php
https://github.com/laravel/cashier-mollie/blob/master/src/Billable.php
MIT
public function guardMollieMandate() { throw_unless($this->validateMollieMandate(), new InvalidMandateException); return true; }
@return bool @throws \Laravel\Cashier\Exceptions\InvalidMandateException
guardMollieMandate
php
laravel/cashier-mollie
src/Billable.php
https://github.com/laravel/cashier-mollie/blob/master/src/Billable.php
MIT
public function redeemCoupon($coupon, $subscription = 'default', $revokeOtherCoupons = true) { $subscription = $this->subscription($subscription); if (! $subscription) { throw new InvalidArgumentException('Unable to apply coupon. Subscription does not exist.'); } /** @var \Laravel\Cashier\Coupon\Coupon $coupon */ $coupon = app()->make(CouponRepository::class)->findOrFail($coupon); $coupon->validateFor($subscription); return DB::transaction(function () use ($coupon, $subscription, $revokeOtherCoupons) { if ($revokeOtherCoupons) { $otherCoupons = $subscription->redeemedCoupons()->active()->get(); $otherCoupons->each->revoke(); } RedeemedCoupon::record($coupon, $subscription); return $this; }); }
Redeem a coupon for the billable's subscription. It will be applied to the upcoming Order. @param string $coupon @param string $subscription @param bool $revokeOtherCoupons @return $this @throws \Illuminate\Contracts\Container\BindingResolutionException @throws \Laravel\Cashier\Exceptions\CouponNotFoundException @throws \Throwable|\Laravel\Cashier\Exceptions\CouponException
redeemCoupon
php
laravel/cashier-mollie
src/Billable.php
https://github.com/laravel/cashier-mollie/blob/master/src/Billable.php
MIT
public function redeemedCoupons() { return $this->morphMany(RedeemedCoupon::class, 'owner'); }
Retrieve the redeemed coupons. @return \Illuminate\Database\Eloquent\Relations\MorphMany
redeemedCoupons
php
laravel/cashier-mollie
src/Billable.php
https://github.com/laravel/cashier-mollie/blob/master/src/Billable.php
MIT
public static function run() { $items = OrderItem::shouldProcess()->get(); $orders = $items->chunkByOwnerAndCurrency()->map(function ($chunk) { return Order::createFromItems($chunk)->processPayment(); }); return $orders; }
Process scheduled OrderItems @return \Illuminate\Support\Collection
run
php
laravel/cashier-mollie
src/Cashier.php
https://github.com/laravel/cashier-mollie/blob/master/src/Cashier.php
MIT
public static function useCurrency($currency, $symbol = null) { static::$currency = $currency; static::useCurrencySymbol($symbol ?: static::guessCurrencySymbol($currency)); }
Set the default currency for this merchant. @param string $currency @param string|null $symbol @return void @throws \Exception
useCurrency
php
laravel/cashier-mollie
src/Cashier.php
https://github.com/laravel/cashier-mollie/blob/master/src/Cashier.php
MIT
public static function useCurrencySymbol($symbol) { static::$currencySymbol = $symbol; }
Set the currency symbol to be used when formatting currency. @param string $symbol @return void
useCurrencySymbol
php
laravel/cashier-mollie
src/Cashier.php
https://github.com/laravel/cashier-mollie/blob/master/src/Cashier.php
MIT
public static function useCurrencyLocale($locale) { static::$currencyLocale = $locale; }
Set the currency locale to be used when formatting currency. @param string $locale @return void
useCurrencyLocale
php
laravel/cashier-mollie
src/Cashier.php
https://github.com/laravel/cashier-mollie/blob/master/src/Cashier.php
MIT
public static function usesCurrency() { return static::$currency; }
Get the currency currently in use. @return string
usesCurrency
php
laravel/cashier-mollie
src/Cashier.php
https://github.com/laravel/cashier-mollie/blob/master/src/Cashier.php
MIT
public static function usesCurrencySymbol() { return static::$currencySymbol; }
Get the currency symbol currently in use. @return string
usesCurrencySymbol
php
laravel/cashier-mollie
src/Cashier.php
https://github.com/laravel/cashier-mollie/blob/master/src/Cashier.php
MIT
public static function usesCurrencyLocale() { return static::$currencyLocale; }
Get the currency locale currently in use. @return string
usesCurrencyLocale
php
laravel/cashier-mollie
src/Cashier.php
https://github.com/laravel/cashier-mollie/blob/master/src/Cashier.php
MIT
public static function formatCurrencyUsing(callable $callback) { static::$formatCurrencyUsing = $callback; }
Set the custom currency formatter. @param callable $callback @return void
formatCurrencyUsing
php
laravel/cashier-mollie
src/Cashier.php
https://github.com/laravel/cashier-mollie/blob/master/src/Cashier.php
MIT
public static function formatAmount(Money $money) { if (static::$formatCurrencyUsing) { return call_user_func(static::$formatCurrencyUsing, $money); } $numberFormatter = new \NumberFormatter(static::$currencyLocale, \NumberFormatter::CURRENCY); $moneyFormatter = new IntlMoneyFormatter($numberFormatter, new ISOCurrencies); return $moneyFormatter->format($money); }
Format the given amount into a displayable currency. @param \Money\Money $money @return string
formatAmount
php
laravel/cashier-mollie
src/Cashier.php
https://github.com/laravel/cashier-mollie/blob/master/src/Cashier.php
MIT
public static function getLocale(Model $owner) { if (method_exists($owner, 'getLocale')) { $locale = $owner->getLocale(); if (! empty($locale)) { return $locale; } } return config('cashier.locale'); }
@param \Illuminate\Database\Eloquent\Model $owner @return null|string
getLocale
php
laravel/cashier-mollie
src/Cashier.php
https://github.com/laravel/cashier-mollie/blob/master/src/Cashier.php
MIT
public static function webhookUrl() { return self::pathFromUrl(config('cashier.webhook_url')); }
Get the webhook relative url. @return string
webhookUrl
php
laravel/cashier-mollie
src/Cashier.php
https://github.com/laravel/cashier-mollie/blob/master/src/Cashier.php
MIT
public static function firstPaymentWebhookUrl() { return self::pathFromUrl(config('cashier.first_payment.webhook_url')); }
Get the first payment webhook relative url. @return string
firstPaymentWebhookUrl
php
laravel/cashier-mollie
src/Cashier.php
https://github.com/laravel/cashier-mollie/blob/master/src/Cashier.php
MIT
public static function ignoreMigrations() { static::$runsMigrations = false; return new static; }
Configure Cashier to not register its migrations. @return static
ignoreMigrations
php
laravel/cashier-mollie
src/Cashier.php
https://github.com/laravel/cashier-mollie/blob/master/src/Cashier.php
MIT
public static function ignoreRoutes() { static::$registersRoutes = false; return new static; }
Configure Cashier to not register its routes. @return static
ignoreRoutes
php
laravel/cashier-mollie
src/Cashier.php
https://github.com/laravel/cashier-mollie/blob/master/src/Cashier.php
MIT
protected static function pathFromUrl($url) { $url_parts = parse_url($url); return preg_replace('/^\//', '', $url_parts['path']); }
Get path from url. @param string $url @return string
pathFromUrl
php
laravel/cashier-mollie
src/Cashier.php
https://github.com/laravel/cashier-mollie/blob/master/src/Cashier.php
MIT
public static function forMollieMandate(Mandate $mandate, $currency) { /** @var GetMollieMethodMinimumAmount $getMinimumAmount */ $getMinimumAmount = app()->make(GetMollieMethodMinimumAmount::class); return $getMinimumAmount->execute($mandate->method, $currency); }
@param \Mollie\Api\Resources\Mandate $mandate @param $currency @return \Money\Money
forMollieMandate
php
laravel/cashier-mollie
src/MinimumPayment.php
https://github.com/laravel/cashier-mollie/blob/master/src/MinimumPayment.php
MIT
public function valid() { return $this->active() || $this->onTrial() || $this->onGracePeriod(); }
Determine if the subscription is valid. @return bool
valid
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function active() { return is_null($this->ends_at) || $this->onTrial() || $this->onGracePeriod(); }
Determine if the subscription is active. @return bool
active
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function ended() { return $this->cancelled() && ! $this->onGracePeriod(); }
Determine if the subscription has ended and the grace period has expired. @return bool
ended
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function onTrial() { return $this->trial_ends_at && $this->trial_ends_at->isFuture(); }
Determine if the subscription is within its trial period. @return bool
onTrial
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function onGracePeriod() { return $this->ends_at && $this->ends_at->isFuture(); }
Determine if the subscription is within its grace period after cancellation. @return bool
onGracePeriod
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function recurring() { return ! $this->onTrial() && ! $this->cancelled(); }
Determine if the subscription is recurring and not on trial. @return bool
recurring
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function cancelled() { return ! is_null($this->ends_at); }
Determine if the subscription is no longer active. @return bool
cancelled
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function getCycleProgressAttribute($now = null, $precision = 5) { $now = $now ?: now(); $cycle_started_at = $this->cycle_started_at->copy(); $cycle_ends_at = $this->cancelled() ? $this->ends_at->copy() : $this->cycle_ends_at->copy(); // Cycle completed if ($cycle_ends_at->lessThanOrEqualTo($now)) { return 1; } // Cycle not yet started if ($cycle_started_at->greaterThanOrEqualTo($now)) { return 0; } $total_cycle_seconds = $cycle_started_at->diffInSeconds($cycle_ends_at); $seconds_progressed = $cycle_started_at->diffInSeconds($now); return round($seconds_progressed / $total_cycle_seconds, $precision); }
Helper function to determine the current billing cycle progress ratio. Ranging from 0 (not started) to 1 (completed). @param Carbon|null $now @param int $precision @return float
getCycleProgressAttribute
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function getCycleLeftAttribute(?Carbon $now = null, ?int $precision = 5) { return (float) 1 - $this->getCycleProgressAttribute($now, $precision); }
Helper function to determine the current billing cycle inverted progress ratio. Ranging from 0 (completed) to 1 (not yet started). @param \Carbon\Carbon|null $now @param int|null $precision @return float
getCycleLeftAttribute
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function swap(string $plan, $invoiceNow = true) { /** @var Plan $newPlan */ $newPlan = app(PlanRepository::class)::findOrFail($plan); $previousPlan = $this->plan; if ($this->cancelled()) { $this->cycle_ends_at = $this->ends_at; $this->ends_at = null; } $applyNewSettings = function () use ($newPlan) { $this->plan = $newPlan->name(); }; $this->restartCycleWithModifications($applyNewSettings, now(), $invoiceNow); Event::dispatch(new SubscriptionPlanSwapped($this, $previousPlan)); return $this; }
Swap the subscription to another plan right now by ending the current billing cycle and starting a new one. A new Order is processed along with the payment. @param string $plan @param bool $invoiceNow @return $this
swap
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function swapAndInvoice($plan) { return $this->swap($plan, true); }
Swap the subscription to a new plan, and invoice immediately. @param string $plan @return $this
swapAndInvoice
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function swapNextCycle(string $plan) { $new_plan = app(PlanRepository::class)::findOrFail($plan); return DB::transaction(function () use ($plan, $new_plan) { $this->next_plan = $plan; $this->removeScheduledOrderItem(); $this->scheduleNewOrderItemAt($this->cycle_ends_at, [], true, $new_plan); $this->save(); return $this; }); }
Schedule this subscription to be swapped to another plan once the current cycle has completed. @param string $plan @return $this
swapNextCycle
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function cancel($reason = SubscriptionCancellationReason::UNKNOWN) { // If the user was on trial, we will set the grace period to end when the trial // would have ended. Otherwise, we'll retrieve the end of the billing cycle // period and make that the end of the grace period for this current user. $grace_ends_at = $this->onTrial() ? $this->trial_ends_at : $this->cycle_ends_at; return $this->cancelAt($grace_ends_at, $reason); }
Cancel the subscription at the end of the billing period. @param string|null $reason @return $this
cancel
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function cancelAt(Carbon $endsAt, $reason = SubscriptionCancellationReason::UNKNOWN) { return DB::transaction(function () use ($reason, $endsAt) { $this->removeScheduledOrderItem(); $this->fill([ 'ends_at' => $endsAt, 'cycle_ends_at' => null, ])->save(); Event::dispatch(new SubscriptionCancelled($this, $reason)); return $this; }); }
Cancel the subscription at the date provided. @param \Carbon\Carbon $endsAt @param string $reason @return $this
cancelAt
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function cancelNow($reason = SubscriptionCancellationReason::UNKNOWN) { return $this->cancelAt(now(), $reason); }
Cancel the subscription immediately. @param string $reason @return $this
cancelNow
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
protected function removeScheduledOrderItem($save = false) { $item = $this->scheduledOrderItem; if ($item && $item->isProcessed(false)) { $item->delete(); } $this->fill(['scheduled_order_item_id' => null]); if ($save) { $this->save(); } return $this; }
Remove the subscription's scheduled order item. Optionally persists the reference removal on the subscription. @param false bool $save @return $this @throws \Exception
removeScheduledOrderItem
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function resume() { if (! $this->cancelled()) { throw new LogicException('Unable to resume a subscription that is not cancelled.'); } if (! $this->onGracePeriod()) { throw new LogicException('Unable to resume a subscription that is not within grace period.'); } return DB::transaction(function () { $item = $this->scheduleNewOrderItemAt($this->ends_at); $this->fill([ 'cycle_ends_at' => $this->ends_at, 'ends_at' => null, 'scheduled_order_item_id' => $item->id, ])->save(); Event::dispatch(new SubscriptionResumed($this)); return $this; }); }
Resume the cancelled subscription. @return $this @throws \LogicException
resume
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function orderItems() { return $this->morphMany(OrderItem::class, 'orderable'); }
Get the order items for this subscription. @return \Illuminate\Database\Eloquent\Relations\MorphMany
orderItems
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function scheduledOrderItem() { return $this->hasOne(OrderItem::class, 'id', 'scheduled_order_item_id'); }
Relation to the scheduled order item, if defined. @return \Illuminate\Database\Eloquent\Relations\HasOne
scheduledOrderItem
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function scheduled_order_item() { return $this->scheduledOrderItem(); }
Relation to the scheduled order item, if defined. @return \Illuminate\Database\Eloquent\Relations\HasOne
scheduled_order_item
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function scheduleNewOrderItemAt(Carbon $process_at, $item_overrides = [], $fill_link = true, Plan $plan = null) { if ($this->scheduled_order_item_id) { throw new LogicException('Cannot schedule a new subscription order item if there is already one scheduled.'); } if (is_null($plan)) { $plan = $this->plan(); } $item = $this->orderItems()->create(array_merge( [ 'owner_id' => $this->owner_id, 'owner_type' => $this->owner_type, 'process_at' => $process_at, 'currency' => $plan->amount()->getCurrency()->getCode(), 'unit_price' => (int) $plan->amount()->getAmount(), 'quantity' => $this->quantity ?: 1, 'tax_percentage' => $this->tax_percentage, 'description' => $plan->description(), ], $item_overrides )); if ($fill_link) { $this->fill([ 'scheduled_order_item_id' => $item->id, ]); } return $item; }
Schedule a new subscription order item at the provided datetime. @param Carbon|null $process_at @param array $item_overrides @param bool $fill_link Indicates whether scheduled_order_item_id field should be filled to point to the newly scheduled order item @param \Laravel\Cashier\Plan\Contracts\Plan $plan @return \Illuminate\Database\Eloquent\Model|\Laravel\Cashier\Order\OrderItem
scheduleNewOrderItemAt
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public static function preprocessOrderItem(OrderItem $item) { /** @var Subscription $subscription */ $subscription = $item->orderable; return $subscription->plan()->orderItemPreprocessors()->handle($item); }
Called right before processing the order item into an order. @param OrderItem $item @return \Laravel\Cashier\Order\OrderItemCollection
preprocessOrderItem
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public static function processOrderItem(OrderItem $item) { /** @var Subscription scheduled_order_item_id */ $subscription = $item->orderable; $plan_swapped = false; $previousPlan = null; if (! empty($subscription->next_plan)) { $plan_swapped = true; $previousPlan = $subscription->plan; $subscription->plan = $subscription->next_plan; $subscription->next_plan = null; } $item = DB::transaction(function () use (&$subscription, $item) { $next_cycle_ends_at = $subscription->cycle_ends_at->copy()->modify('+' . $subscription->plan()->interval()); $subscription->cycle_started_at = $subscription->cycle_ends_at; $subscription->cycle_ends_at = $next_cycle_ends_at; // Requires cleared scheduled order item before continuing $subscription->scheduled_order_item_id = null; $subscription->scheduleNewOrderItemAt($subscription->cycle_ends_at); $subscription->save(); $item->description_extra_lines = [ 'From ' . $subscription->cycle_started_at->format('Y-m-d') . ' to ' . $subscription->cycle_ends_at->format('Y-m-d'), ]; return $item; }); if ($plan_swapped) { Event::dispatch(new SubscriptionPlanSwapped($subscription, $previousPlan)); } return $item; }
Called after processing the order item into an order. @param OrderItem $item @return OrderItem The order item that's being processed
processOrderItem
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function syncTaxPercentage() { return DB::transaction(function () { $this->update([ 'tax_percentage' => $this->owner->taxPercentage(), ]); return $this; }); }
Sync the tax percentage of the owner to the subscription. @return Subscription
syncTaxPercentage
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function plan() { return app(PlanRepository::class)::find($this->plan); }
Get the plan instance for this subscription. @return \Laravel\Cashier\Plan\Plan
plan
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function nextPlan() { return app(PlanRepository::class)::find($this->next_plan); }
Get the plan instance for this subscription's next cycle. @return \Laravel\Cashier\Plan\Plan
nextPlan
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function getCurrencyAttribute() { return optional($this->plan())->amount()->getCurrency()->getCode(); }
Get the currency for this subscription. @example EUR @return string
getCurrencyAttribute
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public static function handlePaymentFailed(OrderItem $item) { $subscription = $item->orderable; $endsAt = $subscription->onTrial() ? $subscription->trial_ends_at : now(); $subscription->cancelAt($endsAt, SubscriptionCancellationReason::PAYMENT_FAILED); }
Handle a failed payment. @param \Laravel\Cashier\Order\OrderItem $item @return void
handlePaymentFailed
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public static function handlePaymentPaid(OrderItem $item) { // Subscriptions are prolonged optimistically (so before payment is being completely processed). }
Handle a paid payment. @param \Laravel\Cashier\Order\OrderItem $item @return void
handlePaymentPaid
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function incrementQuantity(int $count = 1, $invoiceNow = true) { return $this->updateQuantity($this->quantity + $count, $invoiceNow); }
Increment the quantity of the subscription. @param int $count @param bool $invoiceNow @return \Laravel\Cashier\Subscription @throws \Throwable
incrementQuantity
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function incrementAndInvoice($count = 1) { return $this->incrementQuantity($count, true); }
Increment the quantity of the subscription, and invoice immediately. @param int $count @return \Laravel\Cashier\Subscription @throws \Throwable
incrementAndInvoice
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function decrementQuantity(int $count = 1, $invoiceNow = true) { return $this->updateQuantity($this->quantity - $count, $invoiceNow); }
Decrement the quantity of the subscription. @param int $count @param bool $invoiceNow @return \Laravel\Cashier\Subscription @throws \Throwable
decrementQuantity
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function updateQuantity(int $quantity, $invoiceNow = true) { throw_if( $quantity < 1, new LogicException('Subscription quantity must be at least 1.') ); $oldQuantity = $this->quantity; $this->restartCycleWithModifications(function () use ($quantity) { $this->quantity = $quantity; }, now(), $invoiceNow); $this->save(); Event::dispatch(new SubscriptionQuantityUpdated($this, $oldQuantity)); return $this; }
Update the quantity of the subscription. @param int $quantity @param bool $invoiceNow @return $this @throws \Throwable
updateQuantity
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function skipTrial() { $this->trial_ends_at = null; return $this; }
Force the trial to end immediately. This method must be combined with swap, resume, etc. @return $this
skipTrial
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
protected function reimburse(Money $amount, array $overrides = []) { return $this->owner->orderItems()->create(array_merge([ 'process_at' => now(), 'description' => $this->plan()->description(), 'currency' => $amount->getCurrency()->getCode(), 'unit_price' => $amount->getAmount(), 'quantity' => $this->quantity ?: 1, 'tax_percentage' => $this->tax_percentage, ], $overrides)); }
@param \Money\Money $amount @param array $overrides @return OrderItem
reimburse
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
protected function reimburseUnusedTime(?Carbon $now = null) { $now = $now ?: now(); if ($this->onTrial()) { return null; } $plan = $this->plan(); $amount = $plan->amount()->negative()->multiply($this->getCycleLeftAttribute($now)); return $this->reimburse($amount, [ 'description' => $plan->description() ]); }
@param \Carbon\Carbon|null $now @return null|\Laravel\Cashier\Order\OrderItem
reimburseUnusedTime
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function restartCycleWithModifications(\Closure $applyNewSettings, ?Carbon $now = null, $invoiceNow = true) { $now = $now ?: now(); return DB::transaction(function () use ($applyNewSettings, $now, $invoiceNow) { // Wrap up current billing cycle $this->removeScheduledOrderItem(); $reimbursement = $this->reimburseUnusedTime($now); $orderItems = (new OrderItemCollection([$reimbursement]))->filter(); // Apply new subscription settings call_user_func($applyNewSettings); if ($this->onTrial()) { // Reschedule next cycle's OrderItem using the new subscription settings $orderItems[] = $this->scheduleNewOrderItemAt($this->trial_ends_at); } else { // Start a new billing cycle using the new subscription settings // Reset the billing cycle $this->cycle_started_at = $now; $this->cycle_ends_at = $now; // Create a new OrderItem, starting a new billing cycle $orderItems[] = $this->scheduleNewOrderItemAt($now); } $this->save(); if ($invoiceNow) { $order = Order::createFromItems($orderItems); $order->processPayment(); } return $this; }); }
Wrap up the current billing cycle, apply modifications to this subscription and start a new cycle. @param \Closure $applyNewSettings @param \Carbon\Carbon|null $now @param bool $invoiceNow @return \Laravel\Cashier\Subscription
restartCycleWithModifications
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function restartCycle(?Carbon $now = null, $invoiceNow = true) { return $this->restartCycleWithModifications(function () { }, $now, $invoiceNow); }
Wrap up the current billing cycle and start a new cycle. @param \Carbon\Carbon|null $now @param bool $invoiceNow @return \Laravel\Cashier\Subscription
restartCycle
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function redeemedCoupons() { return $this->morphMany(RedeemedCoupon::class, 'model'); }
Any coupons redeemed for this subscription @return \Illuminate\Database\Eloquent\Relations\MorphMany
redeemedCoupons
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function appliedCoupons() { return $this->morphMany(AppliedCoupon::class, 'model'); }
Any coupons applied to this subscription @return \Illuminate\Database\Eloquent\Relations\MorphMany
appliedCoupons
php
laravel/cashier-mollie
src/Subscription.php
https://github.com/laravel/cashier-mollie/blob/master/src/Subscription.php
MIT
public function handle() { if (app()->environment('production')) { $this->alert('Running in production mode.'); if ($this->confirm('Proceed installing Cashier?')) { return; } } $this->comment('Publishing Cashier migrations...'); $this->callSilent('vendor:publish', ['--tag' => 'cashier-migrations']); $this->comment('Publishing Cashier configuration files...'); $this->callSilent('vendor:publish', ['--tag' => 'cashier-configs']); if ($this->option('template')) { $this->callSilent('vendor:publish', ['--tag' => 'cashier-views']); } else { $this->info( 'You can publish the Cashier invoice template so you can modify it. ' . 'Note that this will exclude your template copy from updates by the package maintainers.' ); if ($this->confirm('Publish Cashier invoice template?')) { $this->comment('Publishing Cashier invoice template...'); $this->callSilent('vendor:publish', ['--tag' => 'cashier-views']); } } $this->info('Cashier was installed successfully.'); }
Execute the console command. @return void
handle
php
laravel/cashier-mollie
src/Console/Commands/CashierInstall.php
https://github.com/laravel/cashier-mollie/blob/master/src/Console/Commands/CashierInstall.php
MIT
public function handle() { $orders = Cashier::run(); $this->info('Created ' . $orders->count() . ' orders.'); }
Execute the console command. @return mixed
handle
php
laravel/cashier-mollie
src/Console/Commands/CashierRun.php
https://github.com/laravel/cashier-mollie/blob/master/src/Console/Commands/CashierRun.php
MIT
public function model() { return $this->morphTo(); }
Get the model relation the coupon was applied to. @return \Illuminate\Database\Eloquent\Relations\MorphTo
model
php
laravel/cashier-mollie
src/Coupon/AppliedCoupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/AppliedCoupon.php
MIT
public function orderItems() { return $this->morphMany(OrderItem::class, 'orderable'); }
The OrderItem relation for this applied coupon. @return \Illuminate\Database\Eloquent\Relations\MorphMany
orderItems
php
laravel/cashier-mollie
src/Coupon/AppliedCoupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/AppliedCoupon.php
MIT
public static function preprocessOrderItem(OrderItem $item) { return $item->toCollection(); }
Called right before processing the order item into an order. @param OrderItem $item @return \Laravel\Cashier\Order\OrderItemCollection
preprocessOrderItem
php
laravel/cashier-mollie
src/Coupon/AppliedCoupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/AppliedCoupon.php
MIT
public static function processOrderItem(OrderItem $item) { return $item; }
Called after processing the order item into an order. @param OrderItem $item @return OrderItem The order item that's being processed
processOrderItem
php
laravel/cashier-mollie
src/Coupon/AppliedCoupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/AppliedCoupon.php
MIT
public static function handlePaymentFailed(OrderItem $item) { $item->orderable->delete(); }
Handle a failed payment. @param OrderItem $item @return void
handlePaymentFailed
php
laravel/cashier-mollie
src/Coupon/AppliedCoupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/AppliedCoupon.php
MIT
public static function handlePaymentPaid(OrderItem $item) { // All is taken care of }
Handle a paid payment. @param OrderItem $item @return void
handlePaymentPaid
php
laravel/cashier-mollie
src/Coupon/AppliedCoupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/AppliedCoupon.php
MIT
public function validate(Coupon $coupon, AcceptsCoupons $model) { $this->validateOwnersFirstUse($coupon, $model); return true; }
@param \Laravel\Cashier\Coupon\Coupon $coupon @param \Laravel\Cashier\Coupon\Contracts\AcceptsCoupons $model @return bool @throws \Throwable|CouponException
validate
php
laravel/cashier-mollie
src/Coupon/BaseCouponHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/BaseCouponHandler.php
MIT
public function handle(RedeemedCoupon $redeemedCoupon, OrderItemCollection $items) { $this->markApplied($redeemedCoupon); return $this->apply($redeemedCoupon, $items); }
@param \Laravel\Cashier\Coupon\RedeemedCoupon $redeemedCoupon @param \Laravel\Cashier\Order\OrderItemCollection $items @return \Laravel\Cashier\Order\OrderItemCollection
handle
php
laravel/cashier-mollie
src/Coupon/BaseCouponHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/BaseCouponHandler.php
MIT
public function apply(RedeemedCoupon $redeemedCoupon, OrderItemCollection $items) { return $items->concat( $this->getDiscountOrderItems($items)->save() ); }
@param \Laravel\Cashier\Coupon\RedeemedCoupon $redeemedCoupon @param \Laravel\Cashier\Order\OrderItemCollection $items @return \Laravel\Cashier\Order\OrderItemCollection
apply
php
laravel/cashier-mollie
src/Coupon/BaseCouponHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/BaseCouponHandler.php
MIT
public function validateOwnersFirstUse(Coupon $coupon, AcceptsCoupons $model) { $exists = RedeemedCoupon::whereName($coupon->name()) ->whereOwnerType($model->ownerType()) ->whereOwnerId($model->ownerId()) ->count() > 0; throw_if($exists, new CouponException('You have already used this coupon.')); }
@param \Laravel\Cashier\Coupon\Coupon $coupon @param \Laravel\Cashier\Coupon\Contracts\AcceptsCoupons $model @throws \Throwable @throws \Laravel\Cashier\Exceptions\CouponException
validateOwnersFirstUse
php
laravel/cashier-mollie
src/Coupon/BaseCouponHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/BaseCouponHandler.php
MIT
public function markApplied(RedeemedCoupon $redeemedCoupon) { $appliedCoupon = $this->appliedCoupon = AppliedCoupon::create([ 'redeemed_coupon_id' => $redeemedCoupon->id, 'model_type' => $redeemedCoupon->model_type, 'model_id' => $redeemedCoupon->model_id, ]); $redeemedCoupon->markApplied(); event(new CouponApplied($redeemedCoupon, $appliedCoupon)); return $appliedCoupon; }
@param \Laravel\Cashier\Coupon\RedeemedCoupon $redeemedCoupon @return \Laravel\Cashier\Coupon\AppliedCoupon
markApplied
php
laravel/cashier-mollie
src/Coupon/BaseCouponHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/BaseCouponHandler.php
MIT
protected function makeOrderItem(array $data) { if ($this->appliedCoupon) { return $this->appliedCoupon->orderItems()->make($data); } return OrderItem::make($data); }
Create and return an un-saved OrderItem instance. If a coupon has been applied, the order item will be tied to the coupon. @param array $data @return \Illuminate\Database\Eloquent\Model|\Laravel\Cashier\Order\OrderItem
makeOrderItem
php
laravel/cashier-mollie
src/Coupon/BaseCouponHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/BaseCouponHandler.php
MIT
protected function context($key, $default = null) { return Arr::get($this->context, $key, $default); }
Get an item from the context using "dot" notation. @param $key @param null $default @return mixed
context
php
laravel/cashier-mollie
src/Coupon/BaseCouponHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/BaseCouponHandler.php
MIT
public function __construct(array $defaults, array $coupons) { $this->defaults = $defaults; $this->coupons = array_change_key_case($coupons); }
ConfigCouponRepository constructor. @param array $defaults @param array $coupons
__construct
php
laravel/cashier-mollie
src/Coupon/ConfigCouponRepository.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/ConfigCouponRepository.php
MIT
public function find(string $coupon) { $needle = strtolower($coupon); if (array_key_exists($needle, $this->coupons)) { return $this->buildCoupon($needle); } return null; }
@param string $coupon @return Coupon|null
find
php
laravel/cashier-mollie
src/Coupon/ConfigCouponRepository.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/ConfigCouponRepository.php
MIT
public function findOrFail(string $coupon) { $result = $this->find($coupon); throw_if(is_null($result), CouponNotFoundException::class); return $result; }
@param string $coupon @return Coupon @throws CouponNotFoundException
findOrFail
php
laravel/cashier-mollie
src/Coupon/ConfigCouponRepository.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/ConfigCouponRepository.php
MIT
protected function buildCoupon(string $name) { $couponConfig = array_merge($this->defaults, $this->coupons[$name]); $coupon = new Coupon($name, new $couponConfig['handler'], $couponConfig['context']); return $coupon->withTimes($couponConfig['times']); }
@param string $name @return \Laravel\Cashier\Coupon\Coupon
buildCoupon
php
laravel/cashier-mollie
src/Coupon/ConfigCouponRepository.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/ConfigCouponRepository.php
MIT
public function __construct(string $name, CouponHandler $handler, array $context = []) { $this->name = $name; $this->context = $context; $this->handler = $handler; $this->handler->withContext($context); }
Coupon constructor. @param string $name @param \Laravel\Cashier\Coupon\Contracts\CouponHandler $handler @param array $context
__construct
php
laravel/cashier-mollie
src/Coupon/Coupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/Coupon.php
MIT
public function handler() { return $this->handler; }
@return \Laravel\Cashier\Coupon\Contracts\CouponHandler
handler
php
laravel/cashier-mollie
src/Coupon/Coupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/Coupon.php
MIT
public function times() { return $this->times; }
The number of times the coupon will be applied @return int
times
php
laravel/cashier-mollie
src/Coupon/Coupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/Coupon.php
MIT
public function withTimes($times) { throw_if($times < 1, new \LogicException('Cannot apply coupons less than one time.')); $this->times = $times; return $this; }
@param $times @return \Laravel\Cashier\Coupon\Coupon @throws \LogicException|\Throwable
withTimes
php
laravel/cashier-mollie
src/Coupon/Coupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/Coupon.php
MIT
public function redeemFor(AcceptsCoupons $model) { return RedeemedCoupon::record($this, $model); }
@param \Laravel\Cashier\Coupon\Contracts\AcceptsCoupons $model @return \Laravel\Cashier\Coupon\RedeemedCoupon
redeemFor
php
laravel/cashier-mollie
src/Coupon/Coupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/Coupon.php
MIT
public function validateFor(AcceptsCoupons $model) { $this->handler->validate($this, $model); }
Check if the coupon can be applied to the model @param \Laravel\Cashier\Coupon\Contracts\AcceptsCoupons $model @throws \Throwable|\Laravel\Cashier\Exceptions\CouponException
validateFor
php
laravel/cashier-mollie
src/Coupon/Coupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/Coupon.php
MIT
public function handle(OrderItemCollection $items) { $result = new OrderItemCollection; $items->each(function (OrderItem $item) use (&$result) { if ($item->orderableIsSet()) { $coupons = $this->getActiveCoupons($item->orderable_type, $item->orderable_id); $result = $result->concat($coupons->applyTo($item)); } else { $result->push($item); } }); return $result; }
@param \Laravel\Cashier\Order\OrderItemCollection $items @return \Laravel\Cashier\Order\OrderItemCollection
handle
php
laravel/cashier-mollie
src/Coupon/CouponOrderItemPreprocessor.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/CouponOrderItemPreprocessor.php
MIT
protected function getActiveCoupons($modelType, $modelId) { return RedeemedCoupon::whereModel($modelType, $modelId)->active()->get(); }
@param $modelType @param $modelId @return mixed
getActiveCoupons
php
laravel/cashier-mollie
src/Coupon/CouponOrderItemPreprocessor.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/CouponOrderItemPreprocessor.php
MIT
public function getDiscountOrderItems(OrderItemCollection $items) { if ($items->isEmpty()) { return new OrderItemCollection; } /** @var OrderItem $firstItem */ $firstItem = $items->first(); $unitPrice = $this->unitPrice($firstItem->getTotal()); return $this->makeOrderItem([ 'process_at' => now(), 'owner_type' => $firstItem->owner_type, 'owner_id' => $firstItem->owner_id, 'currency' => $unitPrice->getCurrency()->getCode(), 'unit_price' => $unitPrice->getAmount(), 'quantity' => $this->quantity($firstItem), 'tax_percentage' => $this->taxPercentage($firstItem), 'description' => $this->context('description'), ])->toCollection(); }
@param \Laravel\Cashier\Order\OrderItemCollection $items @return \Laravel\Cashier\Order\OrderItemCollection
getDiscountOrderItems
php
laravel/cashier-mollie
src/Coupon/FixedDiscountHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/FixedDiscountHandler.php
MIT
protected function unitPrice(Money $base) { $discount = mollie_array_to_money($this->context('discount')); if ($this->context('allow_surplus', false) && $discount->greaterThan($base)) { return $base->negative(); } return $discount->negative(); }
@param \Money\Money $base The amount the discount is applied to. @return \Money\Money
unitPrice
php
laravel/cashier-mollie
src/Coupon/FixedDiscountHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/FixedDiscountHandler.php
MIT
protected function quantity(OrderItem $firstItem) { $adaptive = $this->context('adaptive_quantity', false); return $adaptive ? $firstItem->quantity : 1; }
@param \Laravel\Cashier\Order\OrderItem $firstItem @return int
quantity
php
laravel/cashier-mollie
src/Coupon/FixedDiscountHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/FixedDiscountHandler.php
MIT
protected function taxPercentage(OrderItem $firstItem) { $noTax = $this->context('no_tax', true); return $noTax ? 0 : $firstItem->getTaxPercentage(); }
@param \Laravel\Cashier\Order\OrderItem $firstItem @return float|int
taxPercentage
php
laravel/cashier-mollie
src/Coupon/FixedDiscountHandler.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/FixedDiscountHandler.php
MIT
public static function record(Coupon $coupon, AcceptsCoupons $model) { return $model->redeemedCoupons()->create([ 'name' => $coupon->name(), 'times_left' => $coupon->times(), 'owner_type' => $model->ownerType(), 'owner_id' => $model->ownerId(), ]); }
@param \Laravel\Cashier\Coupon\Coupon $coupon @param \Laravel\Cashier\Coupon\Contracts\AcceptsCoupons $model @return \Illuminate\Database\Eloquent\Model|\Laravel\Cashier\Coupon\RedeemedCoupon
record
php
laravel/cashier-mollie
src/Coupon/RedeemedCoupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/RedeemedCoupon.php
MIT
public function coupon() { /** @var CouponRepository $repository */ $repository = app()->make(CouponRepository::class); return $repository->findOrFail($this->name); }
Retrieve the underlying Coupon object. @return Coupon
coupon
php
laravel/cashier-mollie
src/Coupon/RedeemedCoupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/RedeemedCoupon.php
MIT
public function handler() { return $this->coupon()->handler(); }
@return \Laravel\Cashier\Coupon\Contracts\CouponHandler
handler
php
laravel/cashier-mollie
src/Coupon/RedeemedCoupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/RedeemedCoupon.php
MIT
public function model() { return $this->morphTo(); }
Get the model relation the coupon was redeemed for. @return \Illuminate\Database\Eloquent\Relations\MorphTo
model
php
laravel/cashier-mollie
src/Coupon/RedeemedCoupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/RedeemedCoupon.php
MIT
public function applyTo(OrderItemCollection $items) { return $this->coupon()->applyTo($this, $items); }
@param \Laravel\Cashier\Order\OrderItemCollection $items @return \Laravel\Cashier\Order\OrderItemCollection
applyTo
php
laravel/cashier-mollie
src/Coupon/RedeemedCoupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/RedeemedCoupon.php
MIT
public function scopeActive(Builder $query) { return $query->where('times_left', '>', 0); }
Scope a query to only include coupons which are being processed @param \Illuminate\Database\Eloquent\Builder $query @return \Illuminate\Database\Eloquent\Builder
scopeActive
php
laravel/cashier-mollie
src/Coupon/RedeemedCoupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/RedeemedCoupon.php
MIT
public function scopeWhereModel(Builder $query, string $modelType, $modelId) { return $query->whereModelType($modelType)->whereModelId($modelId); }
@param \Illuminate\Database\Eloquent\Builder $query @param string $modelType @param $modelId @return mixed
scopeWhereModel
php
laravel/cashier-mollie
src/Coupon/RedeemedCoupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/RedeemedCoupon.php
MIT
public function newCollection(array $models = []) { return new RedeemedCouponCollection($models); }
Create a new Eloquent Collection instance. @param array $models @return \Illuminate\Database\Eloquent\Collection
newCollection
php
laravel/cashier-mollie
src/Coupon/RedeemedCoupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/RedeemedCoupon.php
MIT
public function revoke() { return tap($this, function () { $this->times_left = 0; $this->save(); }); }
Revoke the redeemed coupon. It will no longer be applied. @return self
revoke
php
laravel/cashier-mollie
src/Coupon/RedeemedCoupon.php
https://github.com/laravel/cashier-mollie/blob/master/src/Coupon/RedeemedCoupon.php
MIT