|
| 1 | +# Cash Driver Provider |
| 2 | + |
| 3 | +<img src="https://preview.dragon-code.pro/cashier-provider/cash.svg?brand=laravel" alt="Cash Driver"/> |
| 4 | + |
| 5 | +[![Stable Version][badge_stable]][link_packagist] |
| 6 | +[![Unstable Version][badge_unstable]][link_packagist] |
| 7 | +[![Total Downloads][badge_downloads]][link_packagist] |
| 8 | +[![License][badge_license]][link_license] |
| 9 | + |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +To get the latest version of `Cash Driver Provider`, simply require the project using [Composer](https://getcomposer.org): |
| 14 | + |
| 15 | +```bash |
| 16 | +$ composer require cashier-provider/cash |
| 17 | +``` |
| 18 | + |
| 19 | +Or manually update `require` block of `composer.json` and run `composer update`. |
| 20 | + |
| 21 | +```json |
| 22 | +{ |
| 23 | + "require": { |
| 24 | + "cashier-provider/cash": "^1.0" |
| 25 | + } |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +## Using |
| 30 | + |
| 31 | +> **Note**: |
| 32 | +> |
| 33 | +> This project is the driver for [`Cashier Provider`](https://github.com/cashier-provider/core). |
| 34 | +
|
| 35 | + |
| 36 | +### Configuration |
| 37 | + |
| 38 | +Add your driver information to the `config/cashier.php` file: |
| 39 | + |
| 40 | +```php |
| 41 | +use App\Models\Payment; |
| 42 | +use App\Payments\Cash as CashDetails; |
| 43 | +use CashierProvider\Cash\Driver as CashDriver; |
| 44 | +use CashierProvider\Core\Constants\Driver; |
| 45 | + |
| 46 | +return [ |
| 47 | + 'payment' => [ |
| 48 | + 'map' => [ |
| 49 | + Payment::TYPE_CASH => 'cash' |
| 50 | + ] |
| 51 | + ], |
| 52 | + |
| 53 | + 'drivers' => [ |
| 54 | + 'cash' => [ |
| 55 | + Driver::DRIVER => CashDriver::class, |
| 56 | + Driver::DETAILS => CashDetails::class, |
| 57 | + ] |
| 58 | + ] |
| 59 | +]; |
| 60 | +``` |
| 61 | + |
| 62 | +### Resource |
| 63 | + |
| 64 | +Create a model resource class inheriting from `CashierProvider\Core\Resources\Model` in your application. |
| 65 | + |
| 66 | +Use the `$this->model` link to refer to the payment model. When executed, the `$model` parameter will contain the payment instance. |
| 67 | + |
| 68 | +```php |
| 69 | +namespace App\Payments; |
| 70 | + |
| 71 | +use CashierProvider\Core\Resources\Model; |
| 72 | + |
| 73 | +class Cash extends Model |
| 74 | +{ |
| 75 | + protected function paymentId(): string |
| 76 | + { |
| 77 | + return (string) $this->model->id; |
| 78 | + } |
| 79 | + |
| 80 | + protected function sum(): float |
| 81 | + { |
| 82 | + return (float) $this->model->sum; |
| 83 | + } |
| 84 | + |
| 85 | + protected function currency(): int |
| 86 | + { |
| 87 | + return $this->model->currency; |
| 88 | + } |
| 89 | + |
| 90 | + protected function createdAt(): Carbon |
| 91 | + { |
| 92 | + return $this->model->created_at; |
| 93 | + } |
| 94 | +} |
| 95 | +``` |
| 96 | + |
| 97 | +### Available Methods And Details Data |
| 98 | + |
| 99 | +```php |
| 100 | +$payment->cashier->external_id |
| 101 | +// Returns transaction ID for this operation |
| 102 | + |
| 103 | +$payment->cashier->details->getStatus(): ?string |
| 104 | +// Returns the text status from the bank |
| 105 | +// For example, `PAID`. |
| 106 | + |
| 107 | +$payment->cashier->details->toArray(): array |
| 108 | +// Returns an array of status. |
| 109 | +// For example, |
| 110 | +// |
| 111 | +// [ |
| 112 | +// 'status' => 'PAID' |
| 113 | +// ] |
| 114 | +``` |
| 115 | + |
| 116 | +[badge_downloads]: https://img.shields.io/packagist/dt/cashier-provider/cash.svg?style=flat-square |
| 117 | + |
| 118 | +[badge_license]: https://img.shields.io/packagist/l/cashier-provider/cash.svg?style=flat-square |
| 119 | + |
| 120 | +[badge_stable]: https://img.shields.io/github/v/release/cashier-provider/cash?label=stable&style=flat-square |
| 121 | + |
| 122 | +[badge_unstable]: https://img.shields.io/badge/unstable-dev--main-orange?style=flat-square |
| 123 | + |
| 124 | +[link_license]: LICENSE |
| 125 | + |
| 126 | +[link_packagist]: https://packagist.org/packages/cashier-provider/cash |
0 commit comments