code
stringlengths
15
9.96M
docstring
stringlengths
1
10.1k
func_name
stringlengths
1
124
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
6
186
url
stringlengths
50
236
license
stringclasses
4 values
public static function useSubscriptionModel($subscriptionModel) { static::$subscriptionModel = $subscriptionModel; }
Set the subscription model class name. @param string $subscriptionModel @return void
useSubscriptionModel
php
laravel/cashier-stripe
src/Cashier.php
https://github.com/laravel/cashier-stripe/blob/master/src/Cashier.php
MIT
public static function useSubscriptionItemModel($subscriptionItemModel) { static::$subscriptionItemModel = $subscriptionItemModel; }
Set the subscription item model class name. @param string $subscriptionItemModel @return void
useSubscriptionItemModel
php
laravel/cashier-stripe
src/Cashier.php
https://github.com/laravel/cashier-stripe/blob/master/src/Cashier.php
MIT
public function subscription() { $model = Cashier::$subscriptionModel; return $this->belongsTo($model, (new $model)->getForeignKey()); }
Get the subscription that the item belongs to. @return \Illuminate\Database\Eloquent\Relations\BelongsTo
subscription
php
laravel/cashier-stripe
src/SubscriptionItem.php
https://github.com/laravel/cashier-stripe/blob/master/src/SubscriptionItem.php
MIT
public function incrementQuantity($count = 1) { $this->updateQuantity($this->quantity + $count); return $this; }
Increment the quantity of the subscription item. @param int $count @return $this @throws \Laravel\Cashier\Exceptions\SubscriptionUpdateFailure
incrementQuantity
php
laravel/cashier-stripe
src/SubscriptionItem.php
https://github.com/laravel/cashier-stripe/blob/master/src/SubscriptionItem.php
MIT
public function incrementAndInvoice($count = 1) { $this->alwaysInvoice(); $this->incrementQuantity($count); return $this; }
Increment the quantity of the subscription item, and invoice immediately. @param int $count @return $this @throws \Laravel\Cashier\Exceptions\IncompletePayment @throws \Laravel\Cashier\Exceptions\SubscriptionUpdateFailure
incrementAndInvoice
php
laravel/cashier-stripe
src/SubscriptionItem.php
https://github.com/laravel/cashier-stripe/blob/master/src/SubscriptionItem.php
MIT
public function decrementQuantity($count = 1) { $this->updateQuantity(max(1, $this->quantity - $count)); return $this; }
Decrement the quantity of the subscription item. @param int $count @return $this @throws \Laravel\Cashier\Exceptions\SubscriptionUpdateFailure
decrementQuantity
php
laravel/cashier-stripe
src/SubscriptionItem.php
https://github.com/laravel/cashier-stripe/blob/master/src/SubscriptionItem.php
MIT
public function updateQuantity($quantity) { $this->subscription->guardAgainstIncomplete(); $stripeSubscriptionItem = $this->updateStripeSubscriptionItem([ 'payment_behavior' => $this->paymentBehavior(), 'proration_behavior' => $this->prorateBehavior(), 'quantity' => $quantity, ]); $this->fill([ 'quantity' => $stripeSubscriptionItem->quantity, ])->save(); $stripeSubscription = $this->subscription->asStripeSubscription(); if ($this->subscription->hasSinglePrice()) { $this->subscription->fill([ 'quantity' => $stripeSubscriptionItem->quantity, ]); } $this->subscription->fill([ 'stripe_status' => $stripeSubscription->status, ])->save(); $this->handlePaymentFailure($this->subscription); return $this; }
Update the quantity of the subscription item. @param int $quantity @return $this @throws \Laravel\Cashier\Exceptions\SubscriptionUpdateFailure
updateQuantity
php
laravel/cashier-stripe
src/SubscriptionItem.php
https://github.com/laravel/cashier-stripe/blob/master/src/SubscriptionItem.php
MIT
public function swap($price, array $options = []) { $this->subscription->guardAgainstIncomplete(); $stripeSubscriptionItem = $this->updateStripeSubscriptionItem(array_merge( array_filter([ 'price' => $price, 'quantity' => $this->quantity, 'payment_behavior' => $this->paymentBehavior(), 'proration_behavior' => $this->prorateBehavior(), 'tax_rates' => $this->subscription->getPriceTaxRatesForPayload($price), ], function ($value) { return ! is_null($value); }), $options)); $this->fill([ 'stripe_product' => $stripeSubscriptionItem->price->product, 'stripe_price' => $stripeSubscriptionItem->price->id, 'quantity' => $stripeSubscriptionItem->quantity, ])->save(); $stripeSubscription = $this->subscription->asStripeSubscription(); if ($this->subscription->hasSinglePrice()) { $this->subscription->fill([ 'stripe_price' => $price, 'quantity' => $stripeSubscriptionItem->quantity, ]); } $this->subscription->fill([ 'stripe_status' => $stripeSubscription->status, ])->save(); $this->handlePaymentFailure($this->subscription); return $this; }
Swap the subscription item to a new Stripe price. @param string $price @param array $options @return $this @throws \Laravel\Cashier\Exceptions\SubscriptionUpdateFailure
swap
php
laravel/cashier-stripe
src/SubscriptionItem.php
https://github.com/laravel/cashier-stripe/blob/master/src/SubscriptionItem.php
MIT
public function swapAndInvoice($price, array $options = []) { $this->alwaysInvoice(); return $this->swap($price, $options); }
Swap the subscription item to a new Stripe price, and invoice immediately. @param string $price @param array $options @return $this @throws \Laravel\Cashier\Exceptions\IncompletePayment @throws \Laravel\Cashier\Exceptions\SubscriptionUpdateFailure
swapAndInvoice
php
laravel/cashier-stripe
src/SubscriptionItem.php
https://github.com/laravel/cashier-stripe/blob/master/src/SubscriptionItem.php
MIT
public function reportUsage($quantity = 1, $timestamp = null) { $timestamp = $timestamp instanceof DateTimeInterface ? $timestamp->getTimestamp() : $timestamp; return $this->subscription->owner->stripe()->subscriptionItems->createUsageRecord($this->stripe_id, [ 'quantity' => $quantity, 'action' => $timestamp ? 'set' : 'increment', 'timestamp' => $timestamp ?? time(), ]); }
Report usage for a metered product. @param int $quantity @param \DateTimeInterface|int|null $timestamp @return \Stripe\UsageRecord
reportUsage
php
laravel/cashier-stripe
src/SubscriptionItem.php
https://github.com/laravel/cashier-stripe/blob/master/src/SubscriptionItem.php
MIT
public function usageRecords($options = []) { return new Collection($this->subscription->owner->stripe()->subscriptionItems->allUsageRecordSummaries( $this->stripe_id, $options )->data); }
Get the usage records for a metered product. @param array $options @return \Illuminate\Support\Collection
usageRecords
php
laravel/cashier-stripe
src/SubscriptionItem.php
https://github.com/laravel/cashier-stripe/blob/master/src/SubscriptionItem.php
MIT
public function updateStripeSubscriptionItem(array $options = []) { return $this->subscription->owner->stripe()->subscriptionItems->update( $this->stripe_id, $options ); }
Update the underlying Stripe subscription item information for the model. @param array $options @return \Stripe\SubscriptionItem
updateStripeSubscriptionItem
php
laravel/cashier-stripe
src/SubscriptionItem.php
https://github.com/laravel/cashier-stripe/blob/master/src/SubscriptionItem.php
MIT
public function asStripeSubscriptionItem(array $expand = []) { return $this->subscription->owner->stripe()->subscriptionItems->retrieve( $this->stripe_id, ['expand' => $expand] ); }
Get the subscription as a Stripe subscription item object. @param array $expand @return \Stripe\SubscriptionItem
asStripeSubscriptionItem
php
laravel/cashier-stripe
src/SubscriptionItem.php
https://github.com/laravel/cashier-stripe/blob/master/src/SubscriptionItem.php
MIT
protected static function newFactory() { return SubscriptionItemFactory::new(); }
Create a new factory instance for the model. @return \Illuminate\Database\Eloquent\Factories\Factory
newFactory
php
laravel/cashier-stripe
src/SubscriptionItem.php
https://github.com/laravel/cashier-stripe/blob/master/src/SubscriptionItem.php
MIT
public function __construct(LoggerInterface $logger) { $this->logger = $logger; }
Create a new Logger instance. @param \Psr\Log\LoggerInterface $logger @return void
__construct
php
laravel/cashier-stripe
src/Logger.php
https://github.com/laravel/cashier-stripe/blob/master/src/Logger.php
MIT
public function __construct($owner = null, $parentInstance = null) { $this->owner = $owner; if ($parentInstance && in_array(AllowsCoupons::class, class_uses_recursive($parentInstance))) { $this->couponId = $parentInstance->couponId; $this->promotionCodeId = $parentInstance->promotionCodeId; $this->allowPromotionCodes = $parentInstance->allowPromotionCodes; } if ($parentInstance && in_array(HandlesTaxes::class, class_uses_recursive($parentInstance))) { $this->customerIpAddress = $parentInstance->customerIpAddress; $this->estimationBillingAddress = $parentInstance->estimationBillingAddress; $this->collectTaxIds = $parentInstance->collectTaxIds; } }
Create a new checkout builder instance. @param \Illuminate\Database\Eloquent\Model|null $owner @param object|null $parentInstance @return void
__construct
php
laravel/cashier-stripe
src/CheckoutBuilder.php
https://github.com/laravel/cashier-stripe/blob/master/src/CheckoutBuilder.php
MIT
public static function make($owner = null, $instance = null) { return new static($owner, $instance); }
Create a new checkout builder instance. @param \Illuminate\Database\Eloquent\Model|null $owner @param object|null $instance @return \Laravel\Cashier\CheckoutBuilder
make
php
laravel/cashier-stripe
src/CheckoutBuilder.php
https://github.com/laravel/cashier-stripe/blob/master/src/CheckoutBuilder.php
MIT
public function __construct($owner, StripeCustomerBalanceTransaction $transaction) { if ($owner->stripe_id !== $transaction->customer) { throw InvalidCustomerBalanceTransaction::invalidOwner($transaction, $owner); } $this->owner = $owner; $this->transaction = $transaction; }
Create a new CustomerBalanceTransaction instance. @param \Illuminate\Database\Eloquent\Model $owner @param \Stripe\CustomerBalanceTransaction $transaction @return void @throws \Laravel\Cashier\Exceptions\InvalidCustomerBalanceTransaction
__construct
php
laravel/cashier-stripe
src/CustomerBalanceTransaction.php
https://github.com/laravel/cashier-stripe/blob/master/src/CustomerBalanceTransaction.php
MIT
public function amount() { return $this->formatAmount($this->rawAmount()); }
Get the total transaction amount. @return string
amount
php
laravel/cashier-stripe
src/CustomerBalanceTransaction.php
https://github.com/laravel/cashier-stripe/blob/master/src/CustomerBalanceTransaction.php
MIT
public function rawAmount() { return $this->transaction->amount; }
Get the raw total transaction amount. @return int
rawAmount
php
laravel/cashier-stripe
src/CustomerBalanceTransaction.php
https://github.com/laravel/cashier-stripe/blob/master/src/CustomerBalanceTransaction.php
MIT
public function endingBalance() { return $this->formatAmount($this->rawEndingBalance()); }
Get the ending balance. @return string
endingBalance
php
laravel/cashier-stripe
src/CustomerBalanceTransaction.php
https://github.com/laravel/cashier-stripe/blob/master/src/CustomerBalanceTransaction.php
MIT
public function rawEndingBalance() { return $this->transaction->ending_balance; }
Get the raw ending balance. @return int
rawEndingBalance
php
laravel/cashier-stripe
src/CustomerBalanceTransaction.php
https://github.com/laravel/cashier-stripe/blob/master/src/CustomerBalanceTransaction.php
MIT
protected function formatAmount($amount) { return Cashier::formatAmount($amount, $this->transaction->currency); }
Format the given amount into a displayable currency. @param int $amount @return string
formatAmount
php
laravel/cashier-stripe
src/CustomerBalanceTransaction.php
https://github.com/laravel/cashier-stripe/blob/master/src/CustomerBalanceTransaction.php
MIT
public function invoice() { return $this->transaction->invoice ? $this->owner->findInvoice($this->transaction->invoice) : null; }
Return the related invoice for this transaction. @return \Laravel\Cashier\Invoice
invoice
php
laravel/cashier-stripe
src/CustomerBalanceTransaction.php
https://github.com/laravel/cashier-stripe/blob/master/src/CustomerBalanceTransaction.php
MIT
public function asStripeCustomerBalanceTransaction() { return $this->transaction; }
Get the Stripe CustomerBalanceTransaction instance. @return \Stripe\CustomerBalanceTransaction
asStripeCustomerBalanceTransaction
php
laravel/cashier-stripe
src/CustomerBalanceTransaction.php
https://github.com/laravel/cashier-stripe/blob/master/src/CustomerBalanceTransaction.php
MIT
public function toArray() { return $this->asStripeCustomerBalanceTransaction()->toArray(); }
Get the instance as an array. @return array
toArray
php
laravel/cashier-stripe
src/CustomerBalanceTransaction.php
https://github.com/laravel/cashier-stripe/blob/master/src/CustomerBalanceTransaction.php
MIT
public function toJson($options = 0) { return json_encode($this->jsonSerialize(), $options); }
Convert the object to its JSON representation. @param int $options @return string
toJson
php
laravel/cashier-stripe
src/CustomerBalanceTransaction.php
https://github.com/laravel/cashier-stripe/blob/master/src/CustomerBalanceTransaction.php
MIT
public function jsonSerialize() { return $this->toArray(); }
[\ReturnTypeWillChange]
jsonSerialize
php
laravel/cashier-stripe
src/CustomerBalanceTransaction.php
https://github.com/laravel/cashier-stripe/blob/master/src/CustomerBalanceTransaction.php
MIT
public function __get($key) { return $this->transaction->{$key}; }
Dynamically get values from the Stripe object. @param string $key @return mixed
__get
php
laravel/cashier-stripe
src/CustomerBalanceTransaction.php
https://github.com/laravel/cashier-stripe/blob/master/src/CustomerBalanceTransaction.php
MIT
public function __construct() { if (config('cashier.webhook.secret')) { $this->middleware(VerifyWebhookSignature::class); } }
Create a new WebhookController instance. @return void
__construct
php
laravel/cashier-stripe
src/Http/Controllers/WebhookController.php
https://github.com/laravel/cashier-stripe/blob/master/src/Http/Controllers/WebhookController.php
MIT
public function handleWebhook(Request $request) { $payload = json_decode($request->getContent(), true); $method = 'handle'.Str::studly(str_replace('.', '_', $payload['type'])); WebhookReceived::dispatch($payload); if (method_exists($this, $method)) { $this->setMaxNetworkRetries(); $response = $this->{$method}($payload); WebhookHandled::dispatch($payload); return $response; } return $this->missingMethod($payload); }
Handle a Stripe webhook call. @param \Illuminate\Http\Request $request @return \Symfony\Component\HttpFoundation\Response
handleWebhook
php
laravel/cashier-stripe
src/Http/Controllers/WebhookController.php
https://github.com/laravel/cashier-stripe/blob/master/src/Http/Controllers/WebhookController.php
MIT
protected function newSubscriptionType(array $payload) { return 'default'; }
Determines the type that should be used when new subscriptions are created from the Stripe dashboard. @param array $payload @return string
newSubscriptionType
php
laravel/cashier-stripe
src/Http/Controllers/WebhookController.php
https://github.com/laravel/cashier-stripe/blob/master/src/Http/Controllers/WebhookController.php
MIT
protected function handleCustomerUpdated(array $payload) { if ($user = $this->getUserByStripeId($payload['data']['object']['id'])) { $user->updateDefaultPaymentMethodFromStripe(); } return $this->successMethod(); }
Handle customer updated. @param array $payload @return \Symfony\Component\HttpFoundation\Response
handleCustomerUpdated
php
laravel/cashier-stripe
src/Http/Controllers/WebhookController.php
https://github.com/laravel/cashier-stripe/blob/master/src/Http/Controllers/WebhookController.php
MIT
protected function handleCustomerDeleted(array $payload) { if ($user = $this->getUserByStripeId($payload['data']['object']['id'])) { $user->subscriptions->each(function (Subscription $subscription) { $subscription->skipTrial()->markAsCanceled(); }); $user->forceFill([ 'stripe_id' => null, 'trial_ends_at' => null, 'pm_type' => null, 'pm_last_four' => null, ])->save(); } return $this->successMethod(); }
Handle deleted customer. @param array $payload @return \Symfony\Component\HttpFoundation\Response
handleCustomerDeleted
php
laravel/cashier-stripe
src/Http/Controllers/WebhookController.php
https://github.com/laravel/cashier-stripe/blob/master/src/Http/Controllers/WebhookController.php
MIT
protected function handlePaymentMethodAutomaticallyUpdated(array $payload) { if ($user = $this->getUserByStripeId($payload['data']['object']['customer'])) { $user->updateDefaultPaymentMethodFromStripe(); } return $this->successMethod(); }
Handle payment method automatically updated by vendor. @param array $payload @return \Symfony\Component\HttpFoundation\Response
handlePaymentMethodAutomaticallyUpdated
php
laravel/cashier-stripe
src/Http/Controllers/WebhookController.php
https://github.com/laravel/cashier-stripe/blob/master/src/Http/Controllers/WebhookController.php
MIT
protected function handleInvoicePaymentActionRequired(array $payload) { if (is_null($notification = config('cashier.payment_notification'))) { return $this->successMethod(); } if ($payload['data']['object']['metadata']['is_on_session_checkout'] ?? false) { return $this->successMethod(); } if ($payload['data']['object']['subscription_details']['metadata']['is_on_session_checkout'] ?? false) { return $this->successMethod(); } if ($user = $this->getUserByStripeId($payload['data']['object']['customer'])) { if (in_array(Notifiable::class, class_uses_recursive($user))) { $payment = new Payment($user->stripe()->paymentIntents->retrieve( $payload['data']['object']['payment_intent'] )); $user->notify(new $notification($payment)); } } return $this->successMethod(); }
Handle payment action required for invoice. @param array $payload @return \Symfony\Component\HttpFoundation\Response
handleInvoicePaymentActionRequired
php
laravel/cashier-stripe
src/Http/Controllers/WebhookController.php
https://github.com/laravel/cashier-stripe/blob/master/src/Http/Controllers/WebhookController.php
MIT
protected function getUserByStripeId($stripeId) { return Cashier::findBillable($stripeId); }
Get the customer instance by Stripe ID. @param string|null $stripeId @return \Laravel\Cashier\Billable|null
getUserByStripeId
php
laravel/cashier-stripe
src/Http/Controllers/WebhookController.php
https://github.com/laravel/cashier-stripe/blob/master/src/Http/Controllers/WebhookController.php
MIT
protected function successMethod($parameters = []) { return new Response('Webhook Handled', 200); }
Handle successful calls on the controller. @param array $parameters @return \Symfony\Component\HttpFoundation\Response
successMethod
php
laravel/cashier-stripe
src/Http/Controllers/WebhookController.php
https://github.com/laravel/cashier-stripe/blob/master/src/Http/Controllers/WebhookController.php
MIT
protected function missingMethod($parameters = []) { return new Response; }
Handle calls to missing methods on the controller. @param array $parameters @return \Symfony\Component\HttpFoundation\Response
missingMethod
php
laravel/cashier-stripe
src/Http/Controllers/WebhookController.php
https://github.com/laravel/cashier-stripe/blob/master/src/Http/Controllers/WebhookController.php
MIT
protected function setMaxNetworkRetries($retries = 3) { Stripe::setMaxNetworkRetries($retries); }
Set the number of automatic retries due to an object lock timeout from Stripe. @param int $retries @return void
setMaxNetworkRetries
php
laravel/cashier-stripe
src/Http/Controllers/WebhookController.php
https://github.com/laravel/cashier-stripe/blob/master/src/Http/Controllers/WebhookController.php
MIT
public function __construct() { $this->middleware(VerifyRedirectUrl::class); }
Create a new PaymentController instance. @return void
__construct
php
laravel/cashier-stripe
src/Http/Controllers/PaymentController.php
https://github.com/laravel/cashier-stripe/blob/master/src/Http/Controllers/PaymentController.php
MIT
public function show($id) { try { $payment = new Payment(Cashier::stripe()->paymentIntents->retrieve( $id, ['expand' => ['payment_method']]) ); } catch (StripeInvalidRequestException $exception) { abort(404, 'Payment not found.'); } $paymentIntent = Arr::only($payment->asStripePaymentIntent()->toArray(), [ 'id', 'status', 'payment_method_types', 'client_secret', 'payment_method', ]); $paymentIntent['payment_method'] = Arr::only($paymentIntent['payment_method'] ?? [], 'id'); return view('cashier::payment', [ 'stripeKey' => config('cashier.key'), 'amount' => $payment->amount(), 'payment' => $payment, 'paymentIntent' => array_filter($paymentIntent), 'paymentMethod' => (string) request('source_type', optional($payment->payment_method)->type), 'errorMessage' => request('redirect_status') === 'failed' ? 'Something went wrong when trying to confirm the payment. Please try again.' : '', 'customer' => $payment->customer(), 'redirect' => url(request('redirect', '/')), ]); }
Display the form to gather additional payment verification for the given payment. @param string $id @return \Illuminate\Contracts\View\View
show
php
laravel/cashier-stripe
src/Http/Controllers/PaymentController.php
https://github.com/laravel/cashier-stripe/blob/master/src/Http/Controllers/PaymentController.php
MIT
public function handle($request, Closure $next) { if (! $redirect = $request->get('redirect')) { return $next($request); } $url = parse_url($redirect); if (isset($url['host']) && $url['host'] !== $request->getHost()) { throw new AccessDeniedHttpException('Redirect host mismatch.'); } return $next($request); }
Handle the incoming request. @param \Illuminate\Http\Request $request @param \Closure $next @return \Illuminate\Http\Response @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
handle
php
laravel/cashier-stripe
src/Http/Middleware/VerifyRedirectUrl.php
https://github.com/laravel/cashier-stripe/blob/master/src/Http/Middleware/VerifyRedirectUrl.php
MIT
public function handle($request, Closure $next) { try { WebhookSignature::verifyHeader( $request->getContent(), $request->header('Stripe-Signature'), config('cashier.webhook.secret'), config('cashier.webhook.tolerance') ); } catch (SignatureVerificationException $exception) { throw new AccessDeniedHttpException($exception->getMessage(), $exception); } return $next($request); }
Handle the incoming request. @param \Illuminate\Http\Request $request @param \Closure $next @return \Illuminate\Http\Response @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
handle
php
laravel/cashier-stripe
src/Http/Middleware/VerifyWebhookSignature.php
https://github.com/laravel/cashier-stripe/blob/master/src/Http/Middleware/VerifyWebhookSignature.php
MIT
public static function exists($owner) { return new static(class_basename($owner)." is already a Stripe customer with ID {$owner->stripe_id}."); }
Create a new CustomerAlreadyCreated instance. @param \Illuminate\Database\Eloquent\Model $owner @return static
exists
php
laravel/cashier-stripe
src/Exceptions/CustomerAlreadyCreated.php
https://github.com/laravel/cashier-stripe/blob/master/src/Exceptions/CustomerAlreadyCreated.php
MIT
public static function invalidOwner(StripeCustomerBalanceTransaction $transaction, $owner) { return new static("The transaction `{$transaction->id}` does not belong to customer `$owner->stripe_id`."); }
Create a new CustomerBalanceTransaction instance. @param \Stripe\CustomerBalanceTransaction $transaction @param \Illuminate\Database\Eloquent\Model $owner @return static
invalidOwner
php
laravel/cashier-stripe
src/Exceptions/InvalidCustomerBalanceTransaction.php
https://github.com/laravel/cashier-stripe/blob/master/src/Exceptions/InvalidCustomerBalanceTransaction.php
MIT
public function __construct(Payment $payment, $message = '', $code = 0, ?Throwable $previous = null) { parent::__construct($message, $code, $previous); $this->payment = $payment; }
Create a new IncompletePayment instance. @param \Laravel\Cashier\Payment $payment @param string $message @param int $code @param \Throwable|null $previous @return void
__construct
php
laravel/cashier-stripe
src/Exceptions/IncompletePayment.php
https://github.com/laravel/cashier-stripe/blob/master/src/Exceptions/IncompletePayment.php
MIT
public static function paymentMethodRequired(Payment $payment) { return new static( $payment, 'The payment attempt failed because of an invalid payment method.' ); }
Create a new IncompletePayment instance with a `payment_action_required` type. @param \Laravel\Cashier\Payment $payment @return static
paymentMethodRequired
php
laravel/cashier-stripe
src/Exceptions/IncompletePayment.php
https://github.com/laravel/cashier-stripe/blob/master/src/Exceptions/IncompletePayment.php
MIT
public static function requiresAction(Payment $payment) { return new static( $payment, 'The payment attempt failed because additional action is required before it can be completed.' ); }
Create a new IncompletePayment instance with a `requires_action` type. @param \Laravel\Cashier\Payment $payment @return static
requiresAction
php
laravel/cashier-stripe
src/Exceptions/IncompletePayment.php
https://github.com/laravel/cashier-stripe/blob/master/src/Exceptions/IncompletePayment.php
MIT
public static function requiresConfirmation(Payment $payment) { return new static( $payment, 'The payment attempt failed because it needs to be confirmed before it can be completed.' ); }
Create a new IncompletePayment instance with a `requires_confirmation` type. @param \Laravel\Cashier\Payment $payment @return static
requiresConfirmation
php
laravel/cashier-stripe
src/Exceptions/IncompletePayment.php
https://github.com/laravel/cashier-stripe/blob/master/src/Exceptions/IncompletePayment.php
MIT
public static function invalidOwner(StripePaymentMethod $paymentMethod, $owner) { return new static( "The payment method `{$paymentMethod->id}`'s customer `{$paymentMethod->customer}` does not belong to this customer `$owner->stripe_id`." ); }
Create a new InvalidPaymentMethod instance. @param \Stripe\PaymentMethod $paymentMethod @param \Illuminate\Database\Eloquent\Model $owner @return static
invalidOwner
php
laravel/cashier-stripe
src/Exceptions/InvalidPaymentMethod.php
https://github.com/laravel/cashier-stripe/blob/master/src/Exceptions/InvalidPaymentMethod.php
MIT
public static function incompleteSubscription(Subscription $subscription) { return new static( "The subscription \"{$subscription->stripe_id}\" cannot be updated because its payment is incomplete." ); }
Create a new SubscriptionUpdateFailure instance. @param \Laravel\Cashier\Subscription $subscription @return static
incompleteSubscription
php
laravel/cashier-stripe
src/Exceptions/SubscriptionUpdateFailure.php
https://github.com/laravel/cashier-stripe/blob/master/src/Exceptions/SubscriptionUpdateFailure.php
MIT
public static function duplicatePrice(Subscription $subscription, $price) { return new static( "The price \"$price\" is already attached to subscription \"{$subscription->stripe_id}\"." ); }
Create a new SubscriptionUpdateFailure instance. @param \Laravel\Cashier\Subscription $subscription @param string $price @return static
duplicatePrice
php
laravel/cashier-stripe
src/Exceptions/SubscriptionUpdateFailure.php
https://github.com/laravel/cashier-stripe/blob/master/src/Exceptions/SubscriptionUpdateFailure.php
MIT
public static function cannotDeleteLastPrice(Subscription $subscription) { return new static( "The price on subscription \"{$subscription->stripe_id}\" cannot be removed because it is the last one." ); }
Create a new SubscriptionUpdateFailure instance. @param \Laravel\Cashier\Subscription $subscription @return static
cannotDeleteLastPrice
php
laravel/cashier-stripe
src/Exceptions/SubscriptionUpdateFailure.php
https://github.com/laravel/cashier-stripe/blob/master/src/Exceptions/SubscriptionUpdateFailure.php
MIT
public static function notYetCreated($owner) { return new static(class_basename($owner).' is not a Stripe customer yet. See the createAsStripeCustomer method.'); }
Create a new InvalidCustomer instance. @param \Illuminate\Database\Eloquent\Model $owner @return static
notYetCreated
php
laravel/cashier-stripe
src/Exceptions/InvalidCustomer.php
https://github.com/laravel/cashier-stripe/blob/master/src/Exceptions/InvalidCustomer.php
MIT
public static function invalidOwner(StripeInvoice $invoice, $owner) { return new static("The invoice `{$invoice->id}` does not belong to this customer `$owner->stripe_id`."); }
Create a new InvalidInvoice instance. @param \Stripe\Invoice $invoice @param \Illuminate\Database\Eloquent\Model $owner @return static
invalidOwner
php
laravel/cashier-stripe
src/Exceptions/InvalidInvoice.php
https://github.com/laravel/cashier-stripe/blob/master/src/Exceptions/InvalidInvoice.php
MIT
public function __construct($billable) { $this->billable = $billable; }
Create a new job instance. @param \Laravel\Cashier\Billable $billable @return void
__construct
php
laravel/cashier-stripe
src/Jobs/SyncCustomerDetails.php
https://github.com/laravel/cashier-stripe/blob/master/src/Jobs/SyncCustomerDetails.php
MIT
public function handle() { $this->billable->syncStripeCustomerDetails(); }
Execute the job. @return void
handle
php
laravel/cashier-stripe
src/Jobs/SyncCustomerDetails.php
https://github.com/laravel/cashier-stripe/blob/master/src/Jobs/SyncCustomerDetails.php
MIT
public function handle() { $webhookEndpoints = Cashier::stripe()->webhookEndpoints; $endpoint = $webhookEndpoints->create(array_filter([ 'enabled_events' => config('cashier.webhook.events') ?: self::DEFAULT_EVENTS, 'url' => $this->option('url') ?? route('cashier.webhook'), 'api_version' => $this->option('api-version') ?? Cashier::STRIPE_VERSION, ])); $this->components->info('The Stripe webhook was created successfully. Retrieve the webhook secret in your Stripe dashboard and define it as an environment variable.'); if ($this->option('disabled')) { $webhookEndpoints->update($endpoint->id, ['disabled' => true]); $this->components->info('The Stripe webhook was disabled as requested. You may enable the webhook via the Stripe dashboard when needed.'); } }
Execute the console command. @return void
handle
php
laravel/cashier-stripe
src/Console/WebhookCommand.php
https://github.com/laravel/cashier-stripe/blob/master/src/Console/WebhookCommand.php
MIT
public function __construct(array $payload) { $this->payload = $payload; }
Create a new event instance. @param array $payload @return void
__construct
php
laravel/cashier-stripe
src/Events/WebhookHandled.php
https://github.com/laravel/cashier-stripe/blob/master/src/Events/WebhookHandled.php
MIT
public function __construct(array $payload) { $this->payload = $payload; }
Create a new event instance. @param array $payload @return void
__construct
php
laravel/cashier-stripe
src/Events/WebhookReceived.php
https://github.com/laravel/cashier-stripe/blob/master/src/Events/WebhookReceived.php
MIT
public function __construct(Payment $payment) { $this->paymentId = $payment->id; $this->amount = $payment->amount(); }
Create a new payment confirmation notification. @param \Laravel\Cashier\Payment $payment @return void
__construct
php
laravel/cashier-stripe
src/Notifications/ConfirmPayment.php
https://github.com/laravel/cashier-stripe/blob/master/src/Notifications/ConfirmPayment.php
MIT
public function via($notifiable) { return ['mail']; }
Get the notification's delivery channels. @param mixed $notifiable @return array
via
php
laravel/cashier-stripe
src/Notifications/ConfirmPayment.php
https://github.com/laravel/cashier-stripe/blob/master/src/Notifications/ConfirmPayment.php
MIT
public function toMail($notifiable) { $url = route('cashier.payment', ['id' => $this->paymentId]); return (new MailMessage) ->subject(__('Confirm Payment')) ->greeting(__('Confirm your :amount payment', ['amount' => $this->amount])) ->line(__('Extra confirmation is needed to process your payment. Please continue to the payment page by clicking on the button below.')) ->action(__('Confirm Payment'), $url); }
Get the mail representation of the notification. @param mixed $notifiable @return \Illuminate\Notifications\Messages\MailMessage
toMail
php
laravel/cashier-stripe
src/Notifications/ConfirmPayment.php
https://github.com/laravel/cashier-stripe/blob/master/src/Notifications/ConfirmPayment.php
MIT
public function tab($description, $amount, array $options = []) { if ($this->isAutomaticTaxEnabled() && ! array_key_exists('price_data', $options)) { throw new LogicException( 'When using automatic tax calculation, you must include "price_data" in the provided options array.' ); } $this->assertCustomerExists(); $options = array_merge([ 'customer' => $this->stripe_id, 'currency' => $this->preferredCurrency(), 'description' => $description, ], $options); if (array_key_exists('price_data', $options)) { $options['price_data'] = array_merge([ 'unit_amount' => $amount, 'currency' => $this->preferredCurrency(), ], $options['price_data']); } elseif (array_key_exists('quantity', $options)) { $options['unit_amount'] = $options['unit_amount'] ?? $amount; } else { $options['amount'] = $amount; } return static::stripe()->invoiceItems->create($options); }
Add an invoice item to the customer's upcoming invoice. @param string $description @param int $amount @param array $options @return \Stripe\InvoiceItem
tab
php
laravel/cashier-stripe
src/Concerns/ManagesInvoices.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesInvoices.php
MIT
public function invoiceFor($description, $amount, array $tabOptions = [], array $invoiceOptions = []) { $this->tab($description, $amount, $tabOptions); return $this->invoice($invoiceOptions); }
Invoice the customer for the given amount and generate an invoice immediately. @param string $description @param int $amount @param array $tabOptions @param array $invoiceOptions @return \Laravel\Cashier\Invoice @throws \Laravel\Cashier\Exceptions\IncompletePayment
invoiceFor
php
laravel/cashier-stripe
src/Concerns/ManagesInvoices.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesInvoices.php
MIT
public function tabPrice($price, $quantity = 1, array $options = []) { $this->assertCustomerExists(); $options = array_merge([ 'customer' => $this->stripe_id, 'price' => $price, 'quantity' => $quantity, ], $options); return static::stripe()->invoiceItems->create($options); }
Add an invoice item for a specific Price ID to the customer's upcoming invoice. @param string $price @param int $quantity @param array $options @return \Stripe\InvoiceItem
tabPrice
php
laravel/cashier-stripe
src/Concerns/ManagesInvoices.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesInvoices.php
MIT
public function invoicePrice($price, $quantity = 1, array $tabOptions = [], array $invoiceOptions = []) { $this->tabPrice($price, $quantity, $tabOptions); return $this->invoice($invoiceOptions); }
Invoice the customer for the given Price ID and generate an invoice immediately. @param string $price @param int $quantity @param array $tabOptions @param array $invoiceOptions @return \Laravel\Cashier\Invoice @throws \Laravel\Cashier\Exceptions\IncompletePayment
invoicePrice
php
laravel/cashier-stripe
src/Concerns/ManagesInvoices.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesInvoices.php
MIT
public function invoice(array $options = []) { try { $payOptions = Arr::only($options, $payOptionKeys = [ 'forgive', 'mandate', 'off_session', 'paid_out_of_band', 'payment_method', 'source', ]); Arr::forget($options, $payOptionKeys); $invoice = $this->createInvoice(array_merge([ 'pending_invoice_items_behavior' => 'include', ], $options)); return $invoice->chargesAutomatically() ? $invoice->pay($payOptions) : $invoice->send(); } catch (StripeCardException) { $payment = new Payment( static::stripe()->paymentIntents->retrieve( $invoice->asStripeInvoice()->refresh()->payment_intent, ['expand' => ['invoice.subscription']] ) ); $payment->validate(); } }
Invoice the customer outside of the regular billing cycle. @param array $options @return \Laravel\Cashier\Invoice @throws \Laravel\Cashier\Exceptions\IncompletePayment
invoice
php
laravel/cashier-stripe
src/Concerns/ManagesInvoices.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesInvoices.php
MIT
public function createInvoice(array $options = []) { $this->assertCustomerExists(); $stripeCustomer = $this->asStripeCustomer(); $parameters = array_merge([ 'automatic_tax' => $this->automaticTaxPayload(), 'customer' => $this->stripe_id, 'currency' => $stripeCustomer->currency ?? config('cashier.currency'), ], $options); if (isset($parameters['subscription'])) { unset($parameters['currency']); } if (array_key_exists('subscription', $parameters)) { unset($parameters['pending_invoice_items_behavior']); } $stripeInvoice = static::stripe()->invoices->create($parameters); return new Invoice($this, $stripeInvoice); }
Create an invoice within Stripe. @param array $options @return \Laravel\Cashier\Invoice
createInvoice
php
laravel/cashier-stripe
src/Concerns/ManagesInvoices.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesInvoices.php
MIT
public function upcomingInvoice(array $options = []) { if (! $this->hasStripeId()) { return; } $parameters = array_merge([ 'automatic_tax' => $this->automaticTaxPayload(), 'customer' => $this->stripe_id, ], $options); try { $stripeInvoice = static::stripe()->invoices->upcoming($parameters); return new Invoice($this, $stripeInvoice, $parameters); } catch (StripeInvalidRequestException $exception) { // } }
Get the customer's upcoming invoice. @param array $options @return \Laravel\Cashier\Invoice|null
upcomingInvoice
php
laravel/cashier-stripe
src/Concerns/ManagesInvoices.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesInvoices.php
MIT
public function findInvoice($id) { $stripeInvoice = null; try { $stripeInvoice = static::stripe()->invoices->retrieve($id); } catch (StripeInvalidRequestException $exception) { // } return $stripeInvoice ? new Invoice($this, $stripeInvoice) : null; }
Find an invoice by ID. @param string $id @return \Laravel\Cashier\Invoice|null
findInvoice
php
laravel/cashier-stripe
src/Concerns/ManagesInvoices.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesInvoices.php
MIT
public function findInvoiceOrFail($id) { try { $invoice = $this->findInvoice($id); } catch (InvalidInvoice $exception) { throw new AccessDeniedHttpException; } if (is_null($invoice)) { throw new NotFoundHttpException; } return $invoice; }
Find an invoice or throw a 404 or 403 error. @param string $id @return \Laravel\Cashier\Invoice @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
findInvoiceOrFail
php
laravel/cashier-stripe
src/Concerns/ManagesInvoices.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesInvoices.php
MIT
public function downloadInvoice($id, array $data = [], $filename = null) { $invoice = $this->findInvoiceOrFail($id); return $filename ? $invoice->downloadAs($filename, $data) : $invoice->download($data); }
Create an invoice download Response. @param string $id @param array $data @param string $filename @return \Symfony\Component\HttpFoundation\Response
downloadInvoice
php
laravel/cashier-stripe
src/Concerns/ManagesInvoices.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesInvoices.php
MIT
public function invoices($includePending = false, $parameters = []) { if (! $this->hasStripeId()) { return new Collection(); } $invoices = []; $parameters = array_merge(['limit' => 24], $parameters); $stripeInvoices = static::stripe()->invoices->all( ['customer' => $this->stripe_id] + $parameters ); // Here we will loop through the Stripe invoices and create our own custom Invoice // instances that have more helper methods and are generally more convenient to // work with than the plain Stripe objects are. Then, we'll return the array. if (! is_null($stripeInvoices)) { foreach ($stripeInvoices->data as $invoice) { if ($invoice->paid || $includePending) { $invoices[] = new Invoice($this, $invoice); } } } return new Collection($invoices); }
Get a collection of the customer's invoices. @param bool $includePending @param array $parameters @return \Illuminate\Support\Collection|\Laravel\Cashier\Invoice[]
invoices
php
laravel/cashier-stripe
src/Concerns/ManagesInvoices.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesInvoices.php
MIT
public function invoicesIncludingPending(array $parameters = []) { return $this->invoices(true, $parameters); }
Get an array of the customer's invoices, including pending invoices. @param array $parameters @return \Illuminate\Support\Collection|\Laravel\Cashier\Invoice[]
invoicesIncludingPending
php
laravel/cashier-stripe
src/Concerns/ManagesInvoices.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesInvoices.php
MIT
public function cursorPaginateInvoices($perPage = 24, array $parameters = [], $cursorName = 'cursor', $cursor = null) { if (! $cursor instanceof Cursor) { $cursor = is_string($cursor) ? Cursor::fromEncoded($cursor) : CursorPaginator::resolveCurrentCursor($cursorName, $cursor); } if (! is_null($cursor)) { if ($cursor->pointsToNextItems()) { $parameters['starting_after'] = $cursor->parameter('id'); } else { $parameters['ending_before'] = $cursor->parameter('id'); } } $invoices = $this->invoices(true, array_merge($parameters, ['limit' => $perPage + 1])); if (! is_null($cursor) && $cursor->pointsToPreviousItems()) { $invoices = $invoices->reverse(); } return new CursorPaginator($invoices, $perPage, $cursor, array_merge([ 'path' => Paginator::resolveCurrentPath(), 'cursorName' => $cursorName, 'parameters' => ['id'], ])); }
Get a cursor paginator for the customer's invoices. @param int|null $perPage @param array $parameters @param string $cursorName @param \Illuminate\Pagination\Cursor|string|null $cursor @return \Illuminate\Contracts\Pagination\CursorPaginator
cursorPaginateInvoices
php
laravel/cashier-stripe
src/Concerns/ManagesInvoices.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesInvoices.php
MIT
public function withTaxIpAddress($ipAddress) { $this->customerIpAddress = $ipAddress; return $this; }
Set the IP address of the customer used to determine the tax location. @return $this
withTaxIpAddress
php
laravel/cashier-stripe
src/Concerns/HandlesTaxes.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/HandlesTaxes.php
MIT
public function withTaxAddress($country, $postalCode = null, $state = null) { $this->estimationBillingAddress = array_filter([ 'country' => $country, 'postal_code' => $postalCode, 'state' => $state, ]); return $this; }
Set a pre-collected billing address used to estimate tax rates when performing "one-off" charges. @param string $country @param string|null $postalCode @param string|null $state @return $this
withTaxAddress
php
laravel/cashier-stripe
src/Concerns/HandlesTaxes.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/HandlesTaxes.php
MIT
protected function automaticTaxPayload() { return array_filter([ 'customer_ip_address' => $this->customerIpAddress, 'enabled' => $this->isAutomaticTaxEnabled(), 'estimation_billing_address' => $this->estimationBillingAddress, ]); }
Get the payload for Stripe automatic tax calculation. @return array|null
automaticTaxPayload
php
laravel/cashier-stripe
src/Concerns/HandlesTaxes.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/HandlesTaxes.php
MIT
protected function isAutomaticTaxEnabled() { return Cashier::$calculatesTaxes; }
Determine if automatic tax is enabled. @return bool
isAutomaticTaxEnabled
php
laravel/cashier-stripe
src/Concerns/HandlesTaxes.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/HandlesTaxes.php
MIT
public function collectTaxIds() { $this->collectTaxIds = true; return $this; }
Indicate that Tax IDs should be collected during a Stripe Checkout session. @return $this
collectTaxIds
php
laravel/cashier-stripe
src/Concerns/HandlesTaxes.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/HandlesTaxes.php
MIT
public function withCoupon($couponId) { $this->couponId = $couponId; return $this; }
The coupon ID to be applied. @param string $couponId @return $this
withCoupon
php
laravel/cashier-stripe
src/Concerns/AllowsCoupons.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/AllowsCoupons.php
MIT
public function withPromotionCode($promotionCodeId) { $this->promotionCodeId = $promotionCodeId; return $this; }
The promotion code ID to apply. @param string $promotionCodeId @return $this
withPromotionCode
php
laravel/cashier-stripe
src/Concerns/AllowsCoupons.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/AllowsCoupons.php
MIT
public function allowPromotionCodes() { $this->allowPromotionCodes = true; return $this; }
Enables user redeemable promotion codes for a Stripe Checkout session. @return $this
allowPromotionCodes
php
laravel/cashier-stripe
src/Concerns/AllowsCoupons.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/AllowsCoupons.php
MIT
protected function checkoutDiscounts() { if ($this->couponId) { return [['coupon' => $this->couponId]]; } if ($this->promotionCodeId) { return [['promotion_code' => $this->promotionCodeId]]; } }
Return the discounts for a Stripe Checkout session. @return array[]|null
checkoutDiscounts
php
laravel/cashier-stripe
src/Concerns/AllowsCoupons.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/AllowsCoupons.php
MIT
public function defaultIncomplete() { $this->paymentBehavior = StripeSubscription::PAYMENT_BEHAVIOR_DEFAULT_INCOMPLETE; return $this; }
Set any new subscription as incomplete when created. @return $this
defaultIncomplete
php
laravel/cashier-stripe
src/Concerns/InteractsWithPaymentBehavior.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/InteractsWithPaymentBehavior.php
MIT
public function allowPaymentFailures() { $this->paymentBehavior = StripeSubscription::PAYMENT_BEHAVIOR_ALLOW_INCOMPLETE; return $this; }
Allow subscription changes even if payment fails. @return $this
allowPaymentFailures
php
laravel/cashier-stripe
src/Concerns/InteractsWithPaymentBehavior.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/InteractsWithPaymentBehavior.php
MIT
public function pendingIfPaymentFails() { $this->paymentBehavior = StripeSubscription::PAYMENT_BEHAVIOR_PENDING_IF_INCOMPLETE; return $this; }
Set any subscription change as pending until payment is successful. @return $this
pendingIfPaymentFails
php
laravel/cashier-stripe
src/Concerns/InteractsWithPaymentBehavior.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/InteractsWithPaymentBehavior.php
MIT
public function errorIfPaymentFails() { $this->paymentBehavior = StripeSubscription::PAYMENT_BEHAVIOR_ERROR_IF_INCOMPLETE; return $this; }
Prevent any subscription change if payment is unsuccessful. @return $this
errorIfPaymentFails
php
laravel/cashier-stripe
src/Concerns/InteractsWithPaymentBehavior.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/InteractsWithPaymentBehavior.php
MIT
public function paymentBehavior() { return $this->paymentBehavior; }
Determine the payment behavior when updating the subscription. @return string
paymentBehavior
php
laravel/cashier-stripe
src/Concerns/InteractsWithPaymentBehavior.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/InteractsWithPaymentBehavior.php
MIT
public function setPaymentBehavior($paymentBehavior) { $this->paymentBehavior = $paymentBehavior; return $this; }
Set the payment behavior for any subscription updates. @param string $paymentBehavior @return $this
setPaymentBehavior
php
laravel/cashier-stripe
src/Concerns/InteractsWithPaymentBehavior.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/InteractsWithPaymentBehavior.php
MIT
public function handlePaymentFailure(Subscription $subscription, $paymentMethod = null) { if ($this->confirmIncompletePayment && $subscription->hasIncompletePayment()) { try { $subscription->latestPayment()->validate(); } catch (IncompletePayment $e) { if ($e->payment->requiresConfirmation()) { try { if ($paymentMethod) { $paymentIntent = $e->payment->confirm(array_merge( $this->paymentConfirmationOptions, [ 'expand' => ['invoice.subscription'], 'payment_method' => $paymentMethod instanceof StripePaymentMethod ? $paymentMethod->id : $paymentMethod, ] )); } else { $paymentIntent = $e->payment->confirm(array_merge( $this->paymentConfirmationOptions, ['expand' => ['invoice.subscription']] )); } } catch (StripeCardException) { $paymentIntent = $e->payment->asStripePaymentIntent(['invoice.subscription']); } $subscription->fill([ 'stripe_status' => $paymentIntent->invoice->subscription->status, ])->save(); if ($subscription->hasIncompletePayment()) { (new Payment($paymentIntent))->refresh(['invoice.subscription'])->validate(); } } else { throw $e; } } } $this->confirmIncompletePayment = true; $this->paymentConfirmationOptions = []; }
Handle a failed payment for the given subscription. @param \Laravel\Cashier\Subscription $subscription @param \Stripe\PaymentMethod|string|null $paymentMethod @return void @throws \Laravel\Cashier\Exceptions\IncompletePayment @internal
handlePaymentFailure
php
laravel/cashier-stripe
src/Concerns/HandlesPaymentFailures.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/HandlesPaymentFailures.php
MIT
public function ignoreIncompletePayments() { $this->confirmIncompletePayment = false; return $this; }
Prevent automatic confirmation of incomplete payments. @return $this
ignoreIncompletePayments
php
laravel/cashier-stripe
src/Concerns/HandlesPaymentFailures.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/HandlesPaymentFailures.php
MIT
public function withPaymentConfirmationOptions(array $options) { $this->paymentConfirmationOptions = $options; return $this; }
Specify the options to be used when confirming a payment intent. @param array $options @return $this
withPaymentConfirmationOptions
php
laravel/cashier-stripe
src/Concerns/HandlesPaymentFailures.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/HandlesPaymentFailures.php
MIT
public function stripeId() { return $this->stripe_id; }
Retrieve the Stripe customer ID. @return string|null
stripeId
php
laravel/cashier-stripe
src/Concerns/ManagesCustomer.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesCustomer.php
MIT
public function hasStripeId() { return ! is_null($this->stripe_id); }
Determine if the customer has a Stripe customer ID. @return bool
hasStripeId
php
laravel/cashier-stripe
src/Concerns/ManagesCustomer.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesCustomer.php
MIT
protected function assertCustomerExists() { if (! $this->hasStripeId()) { throw InvalidCustomer::notYetCreated($this); } }
Determine if the customer has a Stripe customer ID and throw an exception if not. @return void @throws \Laravel\Cashier\Exceptions\InvalidCustomer
assertCustomerExists
php
laravel/cashier-stripe
src/Concerns/ManagesCustomer.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesCustomer.php
MIT
public function createAsStripeCustomer(array $options = []) { if ($this->hasStripeId()) { throw CustomerAlreadyCreated::exists($this); } if (! array_key_exists('name', $options) && $name = $this->stripeName()) { $options['name'] = $name; } if (! array_key_exists('email', $options) && $email = $this->stripeEmail()) { $options['email'] = $email; } if (! array_key_exists('phone', $options) && $phone = $this->stripePhone()) { $options['phone'] = $phone; } if (! array_key_exists('address', $options) && $address = $this->stripeAddress()) { $options['address'] = $address; } if (! array_key_exists('preferred_locales', $options) && $locales = $this->stripePreferredLocales()) { $options['preferred_locales'] = $locales; } if (! array_key_exists('metadata', $options) && $metadata = $this->stripeMetadata()) { $options['metadata'] = $metadata; } // Here we will create the customer instance on Stripe and store the ID of the // user from Stripe. This ID will correspond with the Stripe user instances // and allow us to retrieve users from Stripe later when we need to work. $customer = static::stripe()->customers->create($options); $this->stripe_id = $customer->id; $this->save(); return $customer; }
Create a Stripe customer for the given model. @param array $options @return \Stripe\Customer @throws \Laravel\Cashier\Exceptions\CustomerAlreadyCreated
createAsStripeCustomer
php
laravel/cashier-stripe
src/Concerns/ManagesCustomer.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesCustomer.php
MIT
public function updateStripeCustomer(array $options = []) { return static::stripe()->customers->update( $this->stripe_id, $options ); }
Update the underlying Stripe customer information for the model. @param array $options @return \Stripe\Customer
updateStripeCustomer
php
laravel/cashier-stripe
src/Concerns/ManagesCustomer.php
https://github.com/laravel/cashier-stripe/blob/master/src/Concerns/ManagesCustomer.php
MIT