diff --git a/docs/core/extending/payments.md b/docs/core/extending/payments.md index c1438ae52c..f8f9ddc1c4 100644 --- a/docs/core/extending/payments.md +++ b/docs/core/extending/payments.md @@ -2,7 +2,8 @@ ## Overview -Lunar provides an easy way for you to add your own payment drivers, by default, there is a basic `OfflinePayment` driver that ships with Lunar, additional providers should be added to your Storefront via addons. +Lunar provides an easy way for you to add your own payment drivers, by default, there is a basic `OfflinePayment` driver +that ships with Lunar, additional providers should be added to your Storefront via addons. Below is a list of available payment drivers. @@ -85,7 +86,8 @@ class CustomPayment extends AbstractPayment } ``` -This is the most basic implementation of a driver, you can see we are extending an `AbstractPayment`. This is a class which is provided by Lunar and contains some useful helpers you can utilise in your own driver. +This is the most basic implementation of a driver, you can see we are extending an `AbstractPayment`. This is a class +which is provided by Lunar and contains some useful helpers you can utilise in your own driver. [See available methods](#abstract-class-methods) @@ -95,9 +97,12 @@ This is the most basic implementation of a driver, you can see we are extending public function authorize(); ``` -This is where you'd check the payment details which have been passed in, create any transactions for the order and return the response. +This is where you'd check the payment details which have been passed in, create any transactions for the order and +return the response. -If you're not taking payment straight away, you should set any transactions to the type of `intent`. When you then later capture the payment, we would recommend creating another transaction that is related to that via the `parent_transaction_id`. +If you're not taking payment straight away, you should set any transactions to the type of `intent`. When you then later +capture the payment, we would recommend creating another transaction that is related to that via +the `parent_transaction_id`. #### Capturing payments @@ -105,9 +110,12 @@ If you're not taking payment straight away, you should set any transactions to t public function capture(Transaction $transaction, $amount = 0): PaymentCapture ``` -When you have a transaction that has a type of `intent` the Staff member who is logged into the hub can then decide to capture it so the card used gets charged the amount that has been authorised. +When you have a transaction that has a type of `intent` the Staff member who is logged into the hub can then decide to +capture it so the card used gets charged the amount that has been authorised. -You can pass an optional amount, but be cautious as you generally cannot capture an amount that exceeds the original amount on the `intent` transaction. If you capture an amount less, services like Stripe will treat that as a partial refund and no further captures can take place on that order. +You can pass an optional amount, but be cautious as you generally cannot capture an amount that exceeds the original +amount on the `intent` transaction. If you capture an amount less, services like Stripe will treat that as a partial +refund and no further captures can take place on that order. Here you should create an additional transaction against the order to show how much has been captured. @@ -117,19 +125,20 @@ Here you should create an additional transaction against the order to show how m public function refund(Transaction $transaction, int $amount = 0, $notes = null): PaymentRefund ``` -When refunding a transaction, you can only do so to one that's been captured. If you need to refund an order that hasn't been captured you should instead capture an amount less to what's been authorised. +When refunding a transaction, you can only do so to one that's been captured. If you need to refund an order that hasn't +been captured you should instead capture an amount less to what's been authorised. You should only refund transactions with the type `capture`. - + ## The AbstractPayment class ### Available methods - [`cart`](#cart) - [`order`](#order) -- [`setData`](#setdata) +- [`withData`](#withData) - [`setConfig`](#setconfig) #### `cart` @@ -138,7 +147,8 @@ You should only refund transactions with the type `capture`. public function cart(Cart $cart): self ``` -Sets the `$cart` property on the payment driver. When using the `release` method we recommend expecting a `$cart` instance and checking for the existence of an order. +Sets the `$cart` property on the payment driver. When using the `release` method we recommend expecting a `$cart` +instance and checking for the existence of an order. #### `order` @@ -154,7 +164,8 @@ Sets the `$order` property on the payment driver. public function withData(array $data): self ``` -This method allows you to add any additional data to the payment driver, this can be anything that the payment driver needs to function, for example. +This method allows you to add any additional data to the payment driver, this can be anything that the payment driver +needs to function, for example. ```php Payments::driver('stripe')->withData([ @@ -168,12 +179,13 @@ Payments::driver('stripe')->withData([ public function setConfig(array $config): self ``` -Here you can set up any additional config for this payment driver. By default, this will be called when you register your payment driver and will take any values which are set in `config/lunar/payments.php` for that type. - +Here you can set up any additional config for this payment driver. By default, this will be called when you register +your payment driver and will take any values which are set in `config/lunar/payments.php` for that type. ## Creating transactions -Depending on how your driver works, you're likely going to need to create some transactions depending on different scenarios. +Depending on how your driver works, you're likely going to need to create some transactions depending on different +scenarios. ### Database Schema @@ -181,31 +193,31 @@ Depending on how your driver works, you're likely going to need to create some t Lunar\Models\Transaction ``` -|Field|Description|Example| -|:-|:-|:-| -|id|| -|parent_transaction_id|The ID of the related transaction, nullable| -|order_id|The ID of the order this transaction relates to| -|success| Whether or not the transaction was successful|1 -|type|Whether `intent`,`capture` or `refund`|`intent` -|driver|The driver used i.e. `stripe`|`stripe` -|amount|The amount for the transaction in cents|`10000` -|reference|The reference for the driver to use|`STRIPE_123456` -|status|Usually populated from the payment provider|`success` -|notes|Any additional notes for the transaction| -|card_type|The card type| `visa` -|last_four|The last four digits of the card used|`1234` -|captured_at| The DateTime the transaction was captured| -|meta| Any additional meta info for the transaction| `{"cvc_check": "pass", "address_line1_check": "pass", "address_postal_code_check": "pass"}` -|created_at|| -|updated_at|| - +| Field | Description | Example | +|:----------------------|:------------------------------------------------|:--------------------------------------------------------------------------------------------| +| id | | +| parent_transaction_id | The ID of the related transaction, nullable | +| order_id | The ID of the order this transaction relates to | +| success | Whether or not the transaction was successful | 1 +| type | Whether `intent`,`capture` or `refund` | `intent` +| driver | The driver used i.e. `stripe` | `stripe` +| amount | The amount for the transaction in cents | `10000` +| reference | The reference for the driver to use | `STRIPE_123456` +| status | Usually populated from the payment provider | `success` +| notes | Any additional notes for the transaction | +| card_type | The card type | `visa` +| last_four | The last four digits of the card used | `1234` +| captured_at | The DateTime the transaction was captured | +| meta | Any additional meta info for the transaction | `{"cvc_check": "pass", "address_line1_check": "pass", "address_postal_code_check": "pass"}` +| created_at | | +| updated_at | | ### Best Practices #### Releasing -When releasing a payment, if you're not charging the card straight away, you should create a transaction with type `intent`. This tells Lunar you intend to charge the card at a later date. +When releasing a payment, if you're not charging the card straight away, you should create a transaction with +type `intent`. This tells Lunar you intend to charge the card at a later date. ```php Transaction::create([ @@ -229,7 +241,8 @@ Transaction::create([ If you're already charging the card, you can skip this as you already have payment. 🥳 ::: -When capturing a transaction, you should create an additional transaction with the amount that's been captured. Even if this is the same amount as the `intent` transaction. +When capturing a transaction, you should create an additional transaction with the amount that's been captured. Even if +this is the same amount as the `intent` transaction. ```php $intent = Transaction::whereType('intent')->first(); diff --git a/docs/core/reference/payments.md b/docs/core/reference/payments.md index b5ea78d42f..c4e0479dca 100644 --- a/docs/core/reference/payments.md +++ b/docs/core/reference/payments.md @@ -1,16 +1,19 @@ # Payments :::tip -If you're looking for a guide on how to create your own Payment Driver, or for a more in-depth look at how they work, head over to the [extending section](/core/extending/payments). +If you're looking for a guide on how to create your own Payment Driver, or for a more in-depth look at how they work, +head over to the [extending section](/core/extending/payments). ::: ## Overview -Lunar takes a driver based approach with Payments, meaning you are free to use either add ons to support the provider you wish to use, or you can create your own to meet your exact needs. +Lunar takes a driver based approach with Payments, meaning you are free to use either add ons to support the provider +you wish to use, or you can create your own to meet your exact needs. ## Configuration -All configuration for payments is located in `config/lunar/payments.php`. Here you can specify different types of payments and the driver each one should use. +All configuration for payments is located in `config/lunar/payments.php`. Here you can specify different types of +payments and the driver each one should use. ```php cart(\Lunar\Models\Cart $cart); Set any additional data that the driver may need. ```php -$driver->setData([ +$driver->withData([ 'payment_token' => $token, ]); ``` @@ -59,7 +63,6 @@ Finally, we can authorize the payment. $driver->authorize(); ``` -