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 static function createProcessedFromItem($item, $overrides = [])
{
return static::createProcessedFromItems(new OrderItemCollection([$item]), $overrides);
} | @param $item
@param array $overrides
@return \Laravel\Cashier\Order\Order | createProcessedFromItem | php | laravel/cashier-mollie | src/Order/Order.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php | MIT |
public function processPayment()
{
$this->update(['mollie_payment_id' => 'temp_'.Str::uuid()]);
DB::transaction(function () {
$owner = $this->owner;
// Process user balance, if any
if ($this->getTotal()->getAmount() > 0 && $owner->hasCredit($this->currency)) {
$total = $this->getTotal();
$this->balance_before = $owner->credit($this->currency)->value;
$creditUsed = $owner->maxOutCredit($total);
$this->credit_used = (int) $creditUsed->getAmount();
$this->total_due = $total->subtract($creditUsed)->getAmount();
}
try {
$minimumPaymentAmount = $this->ensureValidMandateAndMinimumPaymentAmountWhenTotalDuePositive();
} catch (InvalidMandateException $e) {
return $this->handlePaymentFailedDueToInvalidMandate();
}
$totalDue = money($this->total_due, $this->currency);
switch (true) {
case $totalDue->isZero():
// No payment processing required
$this->mollie_payment_id = null;
break;
case $totalDue->lessThan($minimumPaymentAmount):
// No payment processing required
$this->mollie_payment_id = null;
// Add credit to the owner's balance
$credit = Credit::addAmountForOwner($owner, money(-($this->total_due), $this->currency));
if (! $owner->hasActiveSubscriptionWithCurrency($this->currency)) {
Event::dispatch(new BalanceTurnedStale($credit));
}
break;
case $totalDue->greaterThanOrEqual($minimumPaymentAmount):
// Create Mollie payment
$payment = (new MandatedPaymentBuilder(
$owner,
"Order " . $this->number,
$totalDue,
url(config('cashier.webhook_url')),
[
'metadata' => [
'temporary_mollie_payment_id' => $this->mollie_payment_id,
],
]
))->create();
$this->mollie_payment_id = $payment->id;
$this->mollie_payment_status = 'open';
break;
default:
break;
}
$this->processed_at = now();
$this->save();
});
Event::dispatch(new OrderProcessed($this));
return $this;
} | Processes the Order into Credit, Refund or Mollie Payment - whichever is appropriate.
@return $this
@throws \Laravel\Cashier\Exceptions\InvalidMandateException | processPayment | php | laravel/cashier-mollie | src/Order/Order.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php | MIT |
public function newCollection(array $models = [])
{
return new OrderCollection($models);
} | Create a new Eloquent Collection instance.
@param array $models
@return \Illuminate\Database\Eloquent\Collection | newCollection | php | laravel/cashier-mollie | src/Order/Order.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php | MIT |
public function invoice($id = null, $date = null)
{
$invoice = (new Invoice(
$this->currency,
$id ?: $this->number,
$date ?: $this->created_at
))->addItems($this->items)
->setStartingBalance($this->getBalanceBefore())
->setCompletedBalance($this->getBalanceAfter())
->setUsedBalance($this->getCreditUsed());
$invoice->setReceiverAddress($this->owner->getInvoiceInformation());
$extra_information = null;
$owner = $this->owner;
if (method_exists($owner, 'getExtraBillingInformation')) {
$extra_information = $owner->getExtraBillingInformation();
if (! empty($extra_information)) {
$extra_information = explode("\n", $extra_information);
if (is_array($extra_information) && ! empty($extra_information)) {
$invoice->setExtraInformation($extra_information);
}
}
}
return $invoice;
} | Get the invoice for this Order.
@param null $id
@param null $date
@return \Laravel\Cashier\Order\Invoice | invoice | php | laravel/cashier-mollie | src/Order/Order.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php | MIT |
public function isProcessed()
{
return ! empty($this->processed_at);
} | Checks whether the order is processed.
@return bool | isProcessed | php | laravel/cashier-mollie | src/Order/Order.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php | MIT |
public function scopeProcessed($query, $processed = true)
{
if ($processed) {
return $query->whereNotNull('processed_at');
}
return $query->whereNull('processed_at');
} | Scope the query to only include processed orders.
@param $query
@param bool $processed
@return Builder | scopeProcessed | php | laravel/cashier-mollie | src/Order/Order.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php | MIT |
public function scopeUnprocessed($query, $unprocessed = true)
{
return $query->processed(! $unprocessed);
} | Scope the query to only include unprocessed orders.
@param $query
@param bool $unprocessed
@return Builder | scopeUnprocessed | php | laravel/cashier-mollie | src/Order/Order.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php | MIT |
public function scopePaymentStatus($query, $status)
{
return $query->where('mollie_payment_status', $status);
} | Scope the query to only include orders with a specific Mollie payment status.
@param $query
@param string $status
@return Builder | scopePaymentStatus | php | laravel/cashier-mollie | src/Order/Order.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php | MIT |
public function scopePaid($query)
{
return $this
->scopePaymentStatus($query, PaymentStatus::STATUS_PAID)
->orWhere('total_due', '=', 0);
} | Scope the query to only include paid orders.
@param $query
@return Builder | scopePaid | php | laravel/cashier-mollie | src/Order/Order.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php | MIT |
public static function findByPaymentId($id)
{
return self::where('mollie_payment_id', $id)->first();
} | Retrieve an Order by the Mollie Payment id.
@param $id
@return self | findByPaymentId | php | laravel/cashier-mollie | src/Order/Order.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php | MIT |
public static function findByPaymentIdOrFail($id)
{
return self::where('mollie_payment_id', $id)->firstOrFail();
} | Retrieve an Order by the Mollie Payment id or throw an Exception if not found.
@param $id
@return self
@throws \Illuminate\Database\Eloquent\ModelNotFoundException | findByPaymentIdOrFail | php | laravel/cashier-mollie | src/Order/Order.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php | MIT |
public function creditApplied()
{
return $this->credit_used <> 0;
} | Checks whether credit was used in the Order.
The credit applied will be reset to 0 when an Order payment fails.
@return bool | creditApplied | php | laravel/cashier-mollie | src/Order/Order.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php | MIT |
public function handlePaymentFailed()
{
return DB::transaction(function () {
if ($this->creditApplied()) {
$this->owner->addCredit($this->getCreditUsed());
}
$this->update([
'mollie_payment_status' => 'failed',
'balance_before' => 0,
'credit_used' => 0,
]);
Event::dispatch(new OrderPaymentFailed($this));
$this->items->each(function (OrderItem $item) {
$item->handlePaymentFailed();
});
$this->owner->validateMollieMandate();
return $this;
});
} | Handles a failed payment for the Order.
Restores any credit used to the customer's balance and resets the credits applied to the Order.
Invokes handlePaymentFailed() on each related OrderItem.
@return $this | handlePaymentFailed | php | laravel/cashier-mollie | src/Order/Order.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php | MIT |
public function handlePaymentFailedDueToInvalidMandate()
{
return DB::transaction(function () {
if ($this->creditApplied()) {
$this->owner->addCredit($this->getCreditUsed());
}
$this->update([
'mollie_payment_id' => null,
'mollie_payment_status' => 'failed',
'balance_before' => 0,
'credit_used' => 0,
'processed_at' => now(),
]);
Event::dispatch(new OrderPaymentFailedDueToInvalidMandate($this));
$this->items->each(function (OrderItem $item) {
$item->handlePaymentFailed();
});
$this->owner->clearMollieMandate();
return $this;
});
} | Handles a failed payment for the Order due to an invalid Mollie payment Mandate.
Restores any credit used to the customer's balance and resets the credits applied to the Order.
Invokes handlePaymentFailed() on each related OrderItem.
@return $this | handlePaymentFailedDueToInvalidMandate | php | laravel/cashier-mollie | src/Order/Order.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php | MIT |
public function handlePaymentPaid()
{
return DB::transaction(function () {
$this->update(['mollie_payment_status' => 'paid']);
Event::dispatch(new OrderPaymentPaid($this));
$this->items->each(function (OrderItem $item) {
$item->handlePaymentPaid();
});
return $this;
});
} | Handles a paid payment for this order.
Invokes handlePaymentPaid() on each related OrderItem.
@return $this | handlePaymentPaid | php | laravel/cashier-mollie | src/Order/Order.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php | MIT |
protected function guardMandate(?Mandate $mandate)
{
if (empty($mandate) || ! $mandate->isValid()) {
throw new InvalidMandateException('Cannot process payment without valid mandate for order id '.$this->id);
}
} | @param \Mollie\Api\Resources\Mandate $mandate
@throws \Laravel\Cashier\Exceptions\InvalidMandateException | guardMandate | php | laravel/cashier-mollie | src/Order/Order.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/Order.php | MIT |
public function invoices()
{
return $this->map(function ($order) {
return $order->invoice();
});
} | Get the invoices for all orders in this collection.
@return \Illuminate\Support\Collection | invoices | php | laravel/cashier-mollie | src/Order/OrderCollection.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderCollection.php | MIT |
public function subscribe($events)
{
$events->listen(
OrderPaymentPaid::class,
self::class . '@handleOrderPaymentPaid'
);
$events->listen(
FirstPaymentPaid::class,
self::class . '@handleFirstPaymentPaid'
);
} | Register the listeners for the subscriber.
@param \Illuminate\Events\Dispatcher $events | subscribe | php | laravel/cashier-mollie | src/Order/OrderInvoiceSubscriber.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderInvoiceSubscriber.php | MIT |
public function orderable()
{
return $this->morphTo('orderable');
} | Get the orderable model for this order item.
@return \Illuminate\Database\Eloquent\Relations\MorphTo | orderable | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function order()
{
return $this->belongsTo(Order::class);
} | Return the order for this order item.
@return \Illuminate\Database\Eloquent\Relations\BelongsTo | order | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function getSubtotalAttribute()
{
return (int) $this->getUnitPrice()->multiply($this->quantity ?: 1)->getAmount();
} | Get the order item total before taxes.
@return int | getSubtotalAttribute | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function getTaxAttribute()
{
$beforeTax = $this->getSubtotal();
return (int) $beforeTax->multiply($this->tax_percentage / 100)->getAmount();
} | Get the order item tax money value.
@return int | getTaxAttribute | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function getTotalAttribute()
{
$beforeTax = $this->getSubtotal();
return (int) $beforeTax->add($this->getTax())->getAmount();
} | Get the order item total after taxes.
@return int | getTotalAttribute | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function scopeProcessed($query, $processed = true)
{
if (! $processed) {
return $query->whereNull('order_id');
}
return $query->whereNotNull('order_id');
} | Scope the query to only include unprocessed order items.
@param $query
@param bool $processed
@return Builder | scopeProcessed | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function scopeUnprocessed($query, $unprocessed = true)
{
return $query->processed(! $unprocessed);
} | Scope the query to only include unprocessed order items.
@param $query
@param bool $unprocessed
@return Builder | scopeUnprocessed | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function newCollection(array $models = [])
{
return new OrderItemCollection($models);
} | Create a new Eloquent Collection instance.
@param array $models
@return OrderItemCollection | newCollection | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function preprocess()
{
if ($this->orderableIsSet()) {
return $this->orderable->preprocessOrderItem($this);
}
return $this->toCollection();
} | Called right before processing the item into an order.
@return \Laravel\Cashier\Order\OrderItemCollection | preprocess | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function process()
{
if ($this->orderableIsSet()) {
$result = $this->orderable->processOrderItem($this);
$result->save();
return $result;
}
return $this;
} | Called after processing the item into an order.
@return $this | process | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function isProcessed($processed = true)
{
return empty($this->order_id) != $processed;
} | Check whether the order item is processed into an order.
@param bool $processed
@return bool | isProcessed | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function getUnitPrice()
{
return $this->toMoney($this->unit_price);
} | Get the unit price before taxes and discounts.
@return \Money\Money | getUnitPrice | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function getTotal()
{
return $this->toMoney($this->total);
} | Get the order item total after taxes and discounts.
@return \Money\Money | getTotal | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function getSubtotal()
{
return $this->toMoney($this->subtotal);
} | Get the order item total before taxes and discounts.
@return \Money\Money | getSubtotal | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function getTaxPercentage()
{
return (float) $this->tax_percentage;
} | The order item tax as a percentage.
@return float
@example 21.5 | getTaxPercentage | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function getDiscount()
{
return $this->toMoney($this->discount);
} | The discount as a money value.
@return \Money\Money | getDiscount | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function getTax()
{
return $this->toMoney($this->tax);
} | The order item tax as a money value.
@return \Money\Money | getTax | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function handlePaymentFailed()
{
if ($this->orderableIsSet()) {
$this->orderable_type::handlePaymentFailed($this);
}
return $this;
} | Handle a failed payment on the order item.
Invokes handlePaymentFailed on the orderable model.
@return $this | handlePaymentFailed | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function handlePaymentPaid()
{
if ($this->orderableIsSet()) {
$this->orderable_type::handlePaymentPaid($this);
}
return $this;
} | Handle a paid payment on the order item.
Invokes handlePaymentPaid on the orderable model.
@return $this | handlePaymentPaid | php | laravel/cashier-mollie | src/Order/OrderItem.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItem.php | MIT |
public function currencies()
{
return collect(array_values($this->pluck('currency')->unique()->all()));
} | Get a collection of distinct currencies in this collection.
@return \Illuminate\Support\Collection | currencies | php | laravel/cashier-mollie | src/Order/OrderItemCollection.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItemCollection.php | MIT |
public function owners()
{
return $this->unique(function ($item) {
return $item->owner_type . $item->owner_id;
})->map(function ($item) {
return $item->owner;
});
} | Get the distinct owners for this collection.
@return \Illuminate\Support\Collection | owners | php | laravel/cashier-mollie | src/Order/OrderItemCollection.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItemCollection.php | MIT |
public function whereOwner($owner)
{
return $this->filter(function ($item) use ($owner) {
return (string) $item->owner_id === (string) $owner->getKey()
&& $item->owner_type === get_class($owner);
});
} | Filter this collection by owner.
@param \Illuminate\Database\Eloquent\Model $owner
@return \Laravel\Cashier\Order\OrderItemCollection | whereOwner | php | laravel/cashier-mollie | src/Order/OrderItemCollection.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItemCollection.php | MIT |
public function chunkByOwner()
{
return $this->owners()->sortBy(function ($owner) {
return get_class($owner) . '_' . $owner->getKey();
})->mapWithKeys(function ($owner) {
$key = get_class($owner) . '_' . $owner->getKey();
return [$key => $this->whereOwner($owner)];
});
} | Returns a collection of OrderItemCollections, grouped by owner.
@return \Illuminate\Support\Collection | chunkByOwner | php | laravel/cashier-mollie | src/Order/OrderItemCollection.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItemCollection.php | MIT |
public function whereCurrency($currency)
{
return $this->where('currency', $currency);
} | Filter this collection by currency symbol.
@param $currency
@return \Laravel\Cashier\Order\OrderItemCollection | whereCurrency | php | laravel/cashier-mollie | src/Order/OrderItemCollection.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItemCollection.php | MIT |
public function chunkByCurrency()
{
return $this->currencies()
->sort()
->mapWithKeys(function ($currency) {
return [$currency => $this->whereCurrency($currency)];
});
} | Returns a collection of OrderItemCollections, grouped by currency symbol.
@return \Illuminate\Support\Collection | chunkByCurrency | php | laravel/cashier-mollie | src/Order/OrderItemCollection.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItemCollection.php | MIT |
public function chunkByOwnerAndCurrency()
{
$result = collect();
$this->chunkByOwner()->each(function ($owners_chunks, $owner_reference) use (&$result) {
$owners_chunks->chunkByCurrency()->each(function ($chunk, $currency) use (&$result, $owner_reference) {
$key = "{$owner_reference}_{$currency}";
$result->put($key, $chunk);
});
});
return $result;
} | Returns a collection of OrderItemCollections, grouped by currency symbol AND owner.
@return \Illuminate\Support\Collection | chunkByOwnerAndCurrency | php | laravel/cashier-mollie | src/Order/OrderItemCollection.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItemCollection.php | MIT |
public function preprocess()
{
/** @var BaseCollection $items */
$items = $this->flatMap(function (OrderItem $item) {
return $item->preprocess();
});
return static::fromBaseCollection($items);
} | Preprocesses the OrderItems.
@return \Laravel\Cashier\Order\OrderItemCollection | preprocess | php | laravel/cashier-mollie | src/Order/OrderItemCollection.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItemCollection.php | MIT |
public static function fromBaseCollection(BaseCollection $collection)
{
return new static($collection->all());
} | Create an OrderItemCollection from a basic Collection.
@param \Illuminate\Support\Collection $collection
@return \Laravel\Cashier\Order\OrderItemCollection | fromBaseCollection | php | laravel/cashier-mollie | src/Order/OrderItemCollection.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItemCollection.php | MIT |
public function save()
{
return $this->map(function (OrderItem $item) {
$item->save();
return $item;
});
} | Persist all items in the collection.
@return \Illuminate\Support\Collection|\Laravel\Cashier\Order\OrderItemCollection | save | php | laravel/cashier-mollie | src/Order/OrderItemCollection.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItemCollection.php | MIT |
public function taxPercentages()
{
return collect(array_values($this->pluck('tax_percentage')->unique()->sort()->all()));
} | Get a collection of distinct tax percentages in this collection.
@return \Illuminate\Support\Collection | taxPercentages | php | laravel/cashier-mollie | src/Order/OrderItemCollection.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItemCollection.php | MIT |
public static function fromArray($value)
{
$preprocessors = collect($value)->map(function ($class) {
return app()->make($class);
});
return static::fromBaseCollection($preprocessors);
} | Initialize the preprocessors from a string array.
@param string[] $value
@return \Laravel\Cashier\Order\OrderItemPreprocessorCollection | fromArray | php | laravel/cashier-mollie | src/Order/OrderItemPreprocessorCollection.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItemPreprocessorCollection.php | MIT |
public function handle(OrderItem $item)
{
$items = $this->reduce(function ($carry, Preprocessor $preprocessor) {
return $preprocessor->handle($carry);
}, $item->toCollection());
return new OrderItemCollection($items);
} | @param \Laravel\Cashier\Order\OrderItem $item
@return \Laravel\Cashier\Order\OrderItemCollection | handle | php | laravel/cashier-mollie | src/Order/OrderItemPreprocessorCollection.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItemPreprocessorCollection.php | MIT |
public static function fromBaseCollection(BaseCollection $collection)
{
return new static($collection->all());
} | Create an OrderItemCollection from a basic Collection.
@param \Illuminate\Support\Collection $collection
@return \Laravel\Cashier\Order\OrderItemPreprocessorCollection | fromBaseCollection | php | laravel/cashier-mollie | src/Order/OrderItemPreprocessorCollection.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderItemPreprocessorCollection.php | MIT |
public function generate()
{
$number = str_pad(
$this->offset + Order::count() + 1,
8,
'0',
STR_PAD_LEFT
);
$numbers = str_split($number, 4);
return implode('-', [
now()->year,
$numbers[0],
$numbers[1],
]);
} | Generate an order reference.
@return string | generate | php | laravel/cashier-mollie | src/Order/OrderNumberGenerator.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/OrderNumberGenerator.php | MIT |
public function handle(OrderItemCollection $items)
{
return $items->save();
} | @param \Laravel\Cashier\Order\OrderItemCollection $items
@return \Laravel\Cashier\Order\OrderItemCollection | handle | php | laravel/cashier-mollie | src/Order/PersistOrderItemsPreprocessor.php | https://github.com/laravel/cashier-mollie/blob/master/src/Order/PersistOrderItemsPreprocessor.php | MIT |
public static function find(string $name)
{
$defaults = config('cashier_plans.defaults');
if (array_key_exists($name, config('cashier_plans.plans'))) {
return static::populatePlan($name, config('cashier_plans.plans.'.$name), $defaults);
}
return null;
} | Get a plan by its name.
@param $name
@return null|\Laravel\Cashier\Plan\Contracts\Plan | find | php | laravel/cashier-mollie | src/Plan/ConfigPlanRepository.php | https://github.com/laravel/cashier-mollie/blob/master/src/Plan/ConfigPlanRepository.php | MIT |
public static function findOrFail(string $name)
{
if (($result = self::find($name)) != null) {
return $result;
} else {
throw new PlanNotFoundException;
}
} | Get a plan by its name or throw an exception.
@param string $name
@return \Laravel\Cashier\Plan\Contracts\Plan
@throws PlanNotFoundException | findOrFail | php | laravel/cashier-mollie | src/Plan/ConfigPlanRepository.php | https://github.com/laravel/cashier-mollie/blob/master/src/Plan/ConfigPlanRepository.php | MIT |
public static function populatePlan(string $name, array $planConfig, array $planDefaults = [])
{
$plan = new Plan($name);
foreach (static::toPlanArray($planConfig, $planDefaults) as $key => $value) {
$key = Str::camel($key);
switch ($key) {
case 'amount':
$plan->setAmount(mollie_array_to_money($value));
break;
case 'firstPaymentAmount':
$plan->setFirstPaymentAmount(mollie_array_to_money($value));
break;
case 'firstPaymentMethod':
$plan->setFirstPaymentMethod($value);
break;
case 'orderItemPreprocessors':
$plan->setOrderItemPreprocessors(Preprocessors::fromArray($value));
break;
default: // call $plan->setKey() if setKey method exists
$method = 'set' . ucfirst($key);
if (method_exists($plan, $method)) {
$plan->$method($value);
}
break;
}
}
return $plan;
} | @param string $name
@param array $planConfig
@param array $planDefaults
@return \Laravel\Cashier\Plan\Plan | populatePlan | php | laravel/cashier-mollie | src/Plan/ConfigPlanRepository.php | https://github.com/laravel/cashier-mollie/blob/master/src/Plan/ConfigPlanRepository.php | MIT |
protected static function toPlanArray(array $planConfig, array $planDefaults = [])
{
$result = array_merge($planDefaults, $planConfig);
// Flatten and prefix first_payment
if (array_key_exists('first_payment', $result)) {
$firstPaymentDefaults = $result['first_payment'];
unset($result['first_payment']);
foreach ($firstPaymentDefaults as $key => $value) {
$newKey = Str::camel('first_payment_' . $key);
$result[ $newKey ] = $value;
}
}
return $result;
} | @param array $planConfig
@param array $planDefaults
@return array | toPlanArray | php | laravel/cashier-mollie | src/Plan/ConfigPlanRepository.php | https://github.com/laravel/cashier-mollie/blob/master/src/Plan/ConfigPlanRepository.php | MIT |
public function setAmount(Money $amount)
{
$this->amount = $amount;
return $this;
} | @param \Money\Money $amount
@return $this | setAmount | php | laravel/cashier-mollie | src/Plan/Plan.php | https://github.com/laravel/cashier-mollie/blob/master/src/Plan/Plan.php | MIT |
public function firstPaymentAmount()
{
return $this->firstPaymentAmount;
} | The amount the customer is charged for a mandate payment.
@return \Money\Money | firstPaymentAmount | php | laravel/cashier-mollie | src/Plan/Plan.php | https://github.com/laravel/cashier-mollie/blob/master/src/Plan/Plan.php | MIT |
public function setFirstPaymentAmount(Money $firstPaymentAmount)
{
$this->firstPaymentAmount = $firstPaymentAmount;
return $this;
} | @param \Money\Money $firstPaymentAmount
@return $this | setFirstPaymentAmount | php | laravel/cashier-mollie | src/Plan/Plan.php | https://github.com/laravel/cashier-mollie/blob/master/src/Plan/Plan.php | MIT |
public function firstPaymentDescription()
{
return $this->firstPaymentDescription;
} | The description for the mandate payment order item.
@return string | firstPaymentDescription | php | laravel/cashier-mollie | src/Plan/Plan.php | https://github.com/laravel/cashier-mollie/blob/master/src/Plan/Plan.php | MIT |
public function setOrderItemPreprocessors(OrderItemPreprocessorCollection $preprocessors)
{
$this->orderItemPreprocessors = $preprocessors;
return $this;
} | @param \Laravel\Cashier\Order\OrderItemPreprocessorCollection $preprocessors
@return \Laravel\Cashier\Plan\Contracts\Plan | setOrderItemPreprocessors | php | laravel/cashier-mollie | src/Plan/Plan.php | https://github.com/laravel/cashier-mollie/blob/master/src/Plan/Plan.php | MIT |
public function __construct(Model $owner, string $name, string $plan, $paymentOptions = [])
{
$this->owner = $owner;
$this->name = $name;
$this->plan = app(PlanRepository::class)::findOrFail($plan);
$this->initializeFirstPaymentBuilder($owner, $paymentOptions);
$this->startSubscription = new StartSubscription($owner, $name, $plan);
} | Create a new subscription builder instance.
@param mixed $owner
@param string $name
@param string $plan
@param array $paymentOptions
@throws \Laravel\Cashier\Exceptions\PlanNotFoundException | __construct | php | laravel/cashier-mollie | src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | MIT |
public function create()
{
$this->validateCoupon();
$actions = new ActionCollection([$this->startSubscription]);
$coupon = $this->startSubscription->coupon();
if ($this->isTrial) {
$taxPercentage = $this->owner->taxPercentage() * 0.01;
$total = $this->plan->firstPaymentAmount();
if ($total->isZero()) {
$vat = $total->subtract($total); // zero VAT
} else {
$vat = $total->divide(1 + $taxPercentage)
->multiply($taxPercentage, $this->roundingMode($total, $taxPercentage));
}
$subtotal = $total->subtract($vat);
$actions[] = new AddGenericOrderItem(
$this->owner,
$subtotal,
$this->plan->firstPaymentDescription(),
$this->roundingMode($total, $taxPercentage)
);
} elseif ($coupon) {
$actions[] = new ApplySubscriptionCouponToPayment($this->owner, $coupon, $actions->processedOrderItems());
}
$this->firstPaymentBuilder->inOrderTo($actions->toArray())->create();
return $this->redirectToCheckout();
} | Create a new subscription. Returns a redirect to Mollie's checkout screen.
@return \Laravel\Cashier\SubscriptionBuilder\RedirectToCheckoutResponse
@throws \Laravel\Cashier\Exceptions\CouponException|\Throwable | create | php | laravel/cashier-mollie | src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | MIT |
public function trialDays(int $trialDays)
{
return $this->trialUntil(Carbon::now()->addDays($trialDays));
} | 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/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | MIT |
public function trialUntil(Carbon $trialUntil)
{
$this->startSubscription->trialUntil($trialUntil);
$this->isTrial = true;
return $this;
} | Specify the ending date of the trial.
@param Carbon $trialUntil
@return $this
@throws \Laravel\Cashier\Exceptions\PlanNotFoundException
@throws \Throwable | trialUntil | php | laravel/cashier-mollie | src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | MIT |
public function skipTrial()
{
$this->isTrial = false;
$this->startSubscription->skipTrial();
return $this;
} | Force the trial to end immediately.
@return \Laravel\Cashier\SubscriptionBuilder\Contracts\SubscriptionBuilder|void | skipTrial | php | laravel/cashier-mollie | src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | MIT |
public function quantity(int $quantity)
{
throw_if($quantity < 1, new \LogicException('Subscription quantity must be at least 1.'));
$this->startSubscription->quantity($quantity);
return $this;
} | Specify the quantity of the subscription.
@param int $quantity
@return $this
@throws \Throwable|\LogicException | quantity | php | laravel/cashier-mollie | src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | MIT |
public function withCoupon(string $coupon)
{
$this->startSubscription->withCoupon($coupon);
return $this;
} | Specify a discount coupon.
@param string $coupon
@return $this
@throws \Laravel\Cashier\Exceptions\CouponNotFoundException | withCoupon | php | laravel/cashier-mollie | src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | MIT |
public function nextPaymentAt(Carbon $nextPaymentAt)
{
$this->startSubscription->nextPaymentAt($nextPaymentAt);
return $this;
} | Override the default next payment date. This is superseded by the trial end date.
@param \Carbon\Carbon $nextPaymentAt
@return $this | nextPaymentAt | php | laravel/cashier-mollie | src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | MIT |
protected function validateCoupon()
{
$coupon = $this->startSubscription->coupon();
if ($coupon) {
$coupon->validateFor(
$this->startSubscription->builder()->makeSubscription()
);
}
} | @throws \Laravel\Cashier\Exceptions\CouponException|\Throwable | validateCoupon | php | laravel/cashier-mollie | src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | MIT |
protected function initializeFirstPaymentBuilder(Model $owner, $paymentOptions = [])
{
$this->firstPaymentBuilder = new FirstPaymentBuilder($owner, $paymentOptions);
$this->firstPaymentBuilder->setFirstPaymentMethod($this->plan->firstPaymentMethod());
$this->firstPaymentBuilder->setRedirectUrl($this->plan->firstPaymentRedirectUrl());
$this->firstPaymentBuilder->setWebhookUrl($this->plan->firstPaymentWebhookUrl());
$this->firstPaymentBuilder->setDescription($this->plan->firstPaymentDescription());
return $this->firstPaymentBuilder;
} | @param \Illuminate\Database\Eloquent\Model $owner
@param array $paymentOptions
@return \Laravel\Cashier\FirstPayment\FirstPaymentBuilder | initializeFirstPaymentBuilder | php | laravel/cashier-mollie | src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | MIT |
public function roundingMode(Money $total, float $taxPercentage)
{
$vat = $total->divide(1 + $taxPercentage)->multiply($taxPercentage);
$subtotal = $total->subtract($vat);
$recalculatedTax = $subtotal->multiply($taxPercentage * 100)->divide(100);
$finalTotal = $subtotal->add($recalculatedTax);
if ($finalTotal->equals($total)) {
return Money::ROUND_HALF_UP;
}
if ($finalTotal->greaterThan($total)) {
return Money::ROUND_UP;
}
return Money::ROUND_DOWN;
} | Format the money as basic decimal
@param \Money\Money $total
@param float $taxPercentage
@return int | roundingMode | php | laravel/cashier-mollie | src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/FirstPaymentSubscriptionBuilder.php | MIT |
public function __construct(Model $owner, string $name, string $plan)
{
$this->name = $name;
$this->owner = $owner;
$this->nextPaymentAt = Carbon::now();
$this->plan = app(PlanRepository::class)::findOrFail($plan);
} | Create a new subscription builder instance.
@param mixed $owner
@param string $name
@param string $plan
@throws \Laravel\Cashier\Exceptions\PlanNotFoundException | __construct | php | laravel/cashier-mollie | src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | MIT |
public function create()
{
$this->owner->guardMollieMandate();
$now = now();
return DB::transaction(function () use ($now) {
$subscription = $this->makeSubscription($now);
$subscription->save();
if ($this->coupon) {
if ($this->validateCoupon) {
$this->coupon->validateFor($subscription);
if ($this->handleCoupon) {
$this->coupon->redeemFor($subscription);
}
}
}
$subscription->scheduleNewOrderItemAt($this->nextPaymentAt);
$subscription->save();
$this->owner->cancelGenericTrial();
return $subscription;
});
} | Create a new Cashier subscription.
@return Subscription
\Laravel\Cashier\Exceptions\CouponException
@throws \Laravel\Cashier\Exceptions\InvalidMandateException | create | php | laravel/cashier-mollie | src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | MIT |
public function makeSubscription($now = null)
{
return $this->owner->subscriptions()->make([
'name' => $this->name,
'plan' => $this->plan->name(),
'quantity' => $this->quantity,
'tax_percentage' => $this->owner->taxPercentage() ?: 0,
'trial_ends_at' => $this->trialExpires,
'cycle_started_at' => $now ?: now(),
'cycle_ends_at' => $this->nextPaymentAt,
]);
} | Prepare a not yet persisted Subscription model
@param null|Carbon $now
@return Subscription $subscription | makeSubscription | php | laravel/cashier-mollie | src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | MIT |
public function trialDays(int $trialDays)
{
return $this->trialUntil(now()->addDays($trialDays));
} | Specify the number of days of the trial.
@param int $trialDays
@return $this | trialDays | php | laravel/cashier-mollie | src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | MIT |
public function trialUntil(Carbon $trialUntil)
{
$this->trialExpires = $trialUntil;
$this->nextPaymentAt = $trialUntil;
return $this;
} | Specify the ending date of the trial.
@param Carbon $trialUntil
@return $this | trialUntil | php | laravel/cashier-mollie | src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | MIT |
public function skipTrial()
{
$this->trialExpires = null;
$this->nextPaymentAt = now();
return $this;
} | Force the trial to end immediately.
@return \Laravel\Cashier\SubscriptionBuilder\Contracts\SubscriptionBuilder|void | skipTrial | php | laravel/cashier-mollie | src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | MIT |
public function quantity(int $quantity)
{
$this->quantity = $quantity;
return $this;
} | Specify the quantity of the subscription.
@param int $quantity
@return $this | quantity | php | laravel/cashier-mollie | src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | MIT |
public function withCoupon(string $coupon)
{
/** @var CouponRepository $repository */
$repository = app()->make(CouponRepository::class);
$this->coupon = $repository->findOrFail($coupon);
return $this;
} | Specify a coupon.
@param string $coupon
@return $this|\Laravel\Cashier\SubscriptionBuilder\Contracts\SubscriptionBuilder
@throws \Laravel\Cashier\Exceptions\CouponNotFoundException | withCoupon | php | laravel/cashier-mollie | src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | MIT |
public function nextPaymentAt(Carbon $nextPaymentAt)
{
$this->nextPaymentAt = $nextPaymentAt;
return $this;
} | Override the default next payment date. This is superseded by the trial end date.
@param \Carbon\Carbon $nextPaymentAt
@return MandatedSubscriptionBuilder | nextPaymentAt | php | laravel/cashier-mollie | src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | MIT |
public function skipCouponValidation()
{
$this->validateCoupon = false;
return $this;
} | Skip validating the coupon when creating the subscription.
@return $this | skipCouponValidation | php | laravel/cashier-mollie | src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | MIT |
public function skipCouponHandling()
{
$this->handleCoupon = false;
return $this;
} | Skip handling the coupon completely when creating the subscription.
@return $this | skipCouponHandling | php | laravel/cashier-mollie | src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/MandatedSubscriptionBuilder.php | MIT |
public static function forPayment(Payment $payment, array $context = [])
{
$response = new static($payment->getCheckoutUrl());
return $response
->setPayment($payment)
->setContext($context);
} | @param \Mollie\Api\Resources\Payment $payment
@param array $context
@return \Laravel\Cashier\SubscriptionBuilder\RedirectToCheckoutResponse | forPayment | php | laravel/cashier-mollie | src/SubscriptionBuilder/RedirectToCheckoutResponse.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/RedirectToCheckoutResponse.php | MIT |
public static function forFirstPaymentSubscriptionBuilder(FirstPaymentSubscriptionBuilder $builder, array $context = [])
{
$payment = $builder->getMandatePaymentBuilder()->getMolliePayment();
return (new static($payment->getCheckoutUrl()))
->setBuilder($builder)
->setPayment($payment)
->setContext($context);
} | @param \Laravel\Cashier\SubscriptionBuilder\FirstPaymentSubscriptionBuilder $builder
@param array $context
@return \Laravel\Cashier\SubscriptionBuilder\RedirectToCheckoutResponse | forFirstPaymentSubscriptionBuilder | php | laravel/cashier-mollie | src/SubscriptionBuilder/RedirectToCheckoutResponse.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/RedirectToCheckoutResponse.php | MIT |
protected function setPayment(Payment $payment)
{
$this->payment = $payment;
return $this;
} | @param \Mollie\Api\Resources\Payment $payment
@return \Laravel\Cashier\SubscriptionBuilder\RedirectToCheckoutResponse | setPayment | php | laravel/cashier-mollie | src/SubscriptionBuilder/RedirectToCheckoutResponse.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/RedirectToCheckoutResponse.php | MIT |
protected function setBuilder(FirstPaymentSubscriptionBuilder $builder)
{
$this->firstPaymentSubscriptionBuilder = $builder;
return $this;
} | @param \Laravel\Cashier\SubscriptionBuilder\FirstPaymentSubscriptionBuilder $builder
@return $this | setBuilder | php | laravel/cashier-mollie | src/SubscriptionBuilder/RedirectToCheckoutResponse.php | https://github.com/laravel/cashier-mollie/blob/master/src/SubscriptionBuilder/RedirectToCheckoutResponse.php | MIT |
protected function formatAmount(Money $amount)
{
return Cashier::formatAmount($amount);
} | Format the given amount into a string.
@param \Money\Money $amount
@return string | formatAmount | php | laravel/cashier-mollie | src/Traits/FormatsAmount.php | https://github.com/laravel/cashier-mollie/blob/master/src/Traits/FormatsAmount.php | MIT |
public function owner()
{
return $this->morphTo('owner');
} | Retrieve the model's owner.
@return \Illuminate\Database\Eloquent\Relations\MorphTo | owner | php | laravel/cashier-mollie | src/Traits/HasOwner.php | https://github.com/laravel/cashier-mollie/blob/master/src/Traits/HasOwner.php | MIT |
public function scopeWhereOwner($query, $owner)
{
return $query
->where('owner_id', $owner->getKey())
->where('owner_type', get_class($owner));
} | Scope a query to only records for a specific owner.
@param \Illuminate\Database\Eloquent\Builder $query
@param mixed $owner
@return \Illuminate\Database\Eloquent\Builder | scopeWhereOwner | php | laravel/cashier-mollie | src/Traits/HasOwner.php | https://github.com/laravel/cashier-mollie/blob/master/src/Traits/HasOwner.php | MIT |
public function mollieCustomerFields()
{
return [
'email' => $this->email,
'name' => $this->name,
//'locale' => $this->locale,
//'metadata' => [
// 'id' => $this->id,
//],
];
} | Returns the customer fields used when creating a Mollie customer
See: https://docs.mollie.com/reference/v2/customers-api/create-customer for the available fields
@return array | mollieCustomerFields | php | laravel/cashier-mollie | src/Traits/PopulatesMollieCustomerFields.php | https://github.com/laravel/cashier-mollie/blob/master/src/Traits/PopulatesMollieCustomerFields.php | MIT |
protected function getPackageProviders($app)
{
return ['Laravel\Cashier\CashierServiceProvider'];
} | @param \Illuminate\Foundation\Application $app
@return array | getPackageProviders | php | laravel/cashier-mollie | tests/BaseTestCase.php | https://github.com/laravel/cashier-mollie/blob/master/tests/BaseTestCase.php | MIT |
protected function runMigrations(Collection $migrations)
{
$migrations->each(function ($migration) {
$this->runMigration($migration['class'], $migration['file_path']);
});
} | Runs a collection of migrations.
@param Collection $migrations | runMigrations | php | laravel/cashier-mollie | tests/BaseTestCase.php | https://github.com/laravel/cashier-mollie/blob/master/tests/BaseTestCase.php | MIT |
protected function assertCarbon(Carbon $expected, Carbon $actual, int $precision_seconds = 5)
{
$expected_min = $expected->copy()->subSeconds($precision_seconds)->startOfSecond();
$expected_max = $expected->copy()->addSeconds($precision_seconds)->startOfSecond();
$actual = $actual->copy()->startOfSecond();
$this->assertTrue(
$actual->between($expected_min, $expected_max),
"Actual datetime [{$actual}] differs more than {$precision_seconds} seconds from expected [{$expected}]."
);
} | Assert that a Carbon datetime is approximately equal to another Carbon datetime.
@param \Carbon\Carbon $expected
@param \Carbon\Carbon $actual
@param int $precision_seconds | assertCarbon | php | laravel/cashier-mollie | tests/BaseTestCase.php | https://github.com/laravel/cashier-mollie/blob/master/tests/BaseTestCase.php | MIT |
protected function withTestNow($now)
{
if (is_string($now)) {
$now = Carbon::parse($now);
}
Carbon::setTestNow($now);
return $this;
} | Set the system test datetime.
@param Carbon|string $now
@return $this | withTestNow | php | laravel/cashier-mollie | tests/BaseTestCase.php | https://github.com/laravel/cashier-mollie/blob/master/tests/BaseTestCase.php | MIT |
protected function withConfiguredPlans()
{
config([
'cashier_plans' => [
'defaults' => [
'first_payment' => [
'redirect_url' => 'https://www.example.com',
'webhook_url' => 'https://www.example.com/webhooks/mollie/first-payment',
'method' => 'ideal',
'amount' => [
'value' => '0.05',
'currency' => 'EUR',
],
'description' => 'Test mandate payment',
],
],
'plans' => [
'monthly-10-1' => [
'amount' => [
'currency' => 'EUR',
'value' => '10.00',
],
'interval' => '1 month',
'description' => 'Monthly payment',
],
'monthly-10-2' => [
'amount' => [
'currency' => 'EUR',
'value' => '20.00',
],
'interval' => '2 months',
'method' => 'directdebit',
'description' => 'Bimonthly payment',
],
'monthly-20-1' => [
'amount' => [
'currency' => 'EUR',
'value' => '20.00',
],
'interval' => '1 month',
'description' => 'Monthly payment premium',
],
'weekly-20-1' => [
'amount' => [
'currency' => 'EUR',
'value' => '20.00',
],
'interval' => '1 weeks',
'description' => 'Twice as expensive monthly subscription',
],
],
],
]);
return $this;
} | Configure some test plans.
@return $this | withConfiguredPlans | php | laravel/cashier-mollie | tests/BaseTestCase.php | https://github.com/laravel/cashier-mollie/blob/master/tests/BaseTestCase.php | MIT |
protected function getUser($persist = true, $overrides = [])
{
$user = factory(User::class)->make($overrides);
if ($persist) {
$user->save();
}
return $user;
} | @param bool $persist
@param array $overrides
@return User | getUser | php | laravel/cashier-mollie | tests/BaseTestCase.php | https://github.com/laravel/cashier-mollie/blob/master/tests/BaseTestCase.php | MIT |
protected function getMollieClientMock()
{
return new MollieApiClient($this->createMock(Client::class));
} | @return \Mollie\Api\MollieApiClient
@throws \Mollie\Api\Exceptions\IncompatiblePlatform
@throws \ReflectionException | getMollieClientMock | php | laravel/cashier-mollie | tests/BaseTestCase.php | https://github.com/laravel/cashier-mollie/blob/master/tests/BaseTestCase.php | MIT |
protected function assertMoney(int $value, string $currency, Money $money)
{
$this->assertEquals($currency, $money->getCurrency()->getCode());
$this->assertEquals($money->getAmount(), $value);
$this->assertTrue(money($value, $currency)->equals($money));
} | @param int $value
@param string $currency
@param \Money\Money $money | assertMoney | php | laravel/cashier-mollie | tests/BaseTestCase.php | https://github.com/laravel/cashier-mollie/blob/master/tests/BaseTestCase.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.