Skip to content

Commit 4541384

Browse files
committed
update docs
1 parent 2b56dad commit 4541384

19 files changed

+114
-150
lines changed

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Now we make transactions.
5959

6060
```php
6161
$user = User::first();
62-
$user->balance; // 0
62+
$user->balanceInt; // 0
6363

6464
$user->deposit(10);
6565
$user->balance; // 10
@@ -116,11 +116,6 @@ class Item extends Model implements Product
116116
'description' => 'Purchase of Product #' . $this->id,
117117
];
118118
}
119-
120-
public function getUniqueId(): string
121-
{
122-
return (string)$this->getKey();
123-
}
124119
}
125120
```
126121

docs/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Introduction
22

3-
How long does it take to add virtual cards to the project? Hah, we'll see.
4-
53
---
64

75
![Laravel Wallet](https://user-images.githubusercontent.com/5111255/48687709-a7c2fa00-ebd3-11e8-8714-c4f3efe93f02.png)

docs/basic-usage.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ class Item extends Model implements Product
7171
'description' => 'Purchase of Product #' . $this->id,
7272
];
7373
}
74-
75-
public function getUniqueId(): string
76-
{
77-
return (string)$this->getKey();
78-
}
7974
}
8075
```
8176

docs/cart.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,9 @@ class Item extends Model implements Product
4545
{
4646
return [
4747
'title' => $this->title,
48-
'description' => 'Purchase of Product #' . $this->getUniqueId(),
48+
'description' => 'Purchase of Product #' . $this->getKey(),
4949
];
5050
}
51-
52-
public function getUniqueId(): string
53-
{
54-
return (string)$this->getKey();
55-
}
5651
}
5752
```
5853

@@ -86,6 +81,7 @@ foreach ($products as $product) {
8681
}
8782

8883
$user->deposit($cart->getTotal());
84+
$user->balanceInt; // 15127
8985
$user->balanceFloat; // 151.27
9086

9187
(bool)$user->payCart($cart); // true

docs/confirm.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class UserConfirm extends Model implements Wallet, Confirmable
1414
}
1515
```
1616

17+
> You can only confirm the transaction with the wallet you paid with.
18+
1719
### Example:
1820

1921
Sometimes you need to create an operation and confirm its field.

docs/deposit.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Check the user's balance.
2424

2525
```php
2626
$user->balance; // 0
27+
$user->balanceInt; // 0
2728
```
2829

2930
The balance is zero, which is what we expected.
@@ -32,6 +33,7 @@ Put it on his 10 cents account.
3233
```php
3334
$user->deposit(10);
3435
$user->balance; // 10
36+
$user->balanceInt; // 10
3537
```
3638

3739
Wow! The balance is 10 cents, the money is credited.

docs/dist/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/exchange.md

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,6 @@ $user->createWallet([
1212
]);
1313
```
1414

15-
> Management via config file is deprecated.
16-
> Create wallets with parameter in meta.currency.
17-
> In the 7.x release, the ability to specify the currency through wallet.php will be removed.
18-
19-
Currencies are configured in the general configuration file `config/wallet.php`.
20-
21-
```php
22-
'currencies' => [
23-
'xbtc' => 'BTC',
24-
'dollar' => 'USD',
25-
'ruble' => 'RUB',
26-
],
27-
```
28-
29-
The key in the configuration is the `slug` of your wallet.
30-
Value, this is the currency of your wallet.
31-
3215
Service for working with currencies you need to write yourself or
3316
use [library](https://github.com/bavix/laravel-wallet-swap).
3417

@@ -38,42 +21,38 @@ We will write a simple service.
3821
We will take the data from the array, and not from the database.
3922

4023
```php
41-
use Bavix\Wallet\Interfaces\Wallet;
42-
use Bavix\Wallet\Services\WalletServiceLegacy;
43-
use Illuminate\Support\Arr;
24+
use Bavix\Wallet\Internal\Service\MathServiceInterface;
25+
use Bavix\Wallet\Services\ExchangeServiceInterface;
4426

45-
class MyRateService extends \Bavix\Wallet\Simple\Rate
27+
class MyExchangeService implements ExchangeServiceInterface
4628
{
47-
48-
// list of exchange rates (take from the database)
49-
protected $rates = [
29+
private array $rates = [
5030
'USD' => [
5131
'RUB' => 67.61,
5232
],
53-
'RUB' => [
54-
'USD' => 0.0147907114,
55-
],
5633
];
5734

58-
protected function rate(Wallet $wallet)
35+
private MathServiceInterface $mathService;
36+
37+
public function __construct(MathServiceInterface $mathService)
5938
{
60-
$from = app(WalletServiceLegacy::class)->getWallet($this->withCurrency);
61-
$to = app(WalletServiceLegacy::class)->getWallet($wallet);
62-
63-
return Arr::get(
64-
Arr::get($this->rates, $from->currency, []),
65-
$to->currency,
66-
1
67-
);
39+
$this->mathService = $mathService;
40+
41+
foreach ($this->rates as $from => $rates) {
42+
foreach ($rates as $to => $rate) {
43+
if (empty($this->rates[$to][$from])) {
44+
$this->rates[$to][$from] = $this->mathService->div(1, $rate);
45+
}
46+
}
47+
}
6848
}
6949

70-
public function convertTo(Wallet $wallet)
50+
/** @param float|int|string $amount */
51+
public function convertTo(string $fromCurrency, string $toCurrency, $amount): string
7152
{
72-
return parent::convertTo($wallet) * $this->rate($wallet);
53+
return $this->mathService->mul($amount, $this->rates[$fromCurrency][$toCurrency] ?? 1);
7354
}
74-
7555
}
76-
7756
```
7857

7958
#### Service Registration
@@ -83,8 +62,8 @@ The service you wrote must be registered, this is done in the file `config/walle
8362
```php
8463
return [
8564
// ...
86-
'package' => [
87-
'rateable' => MyRateService::class,
65+
'services' => [
66+
'exchange' => MyExchangeService::class,
8867
// ...
8968
],
9069
// ...
@@ -98,12 +77,12 @@ Create two wallets.
9877
```php
9978
$usd = $user->createWallet([
10079
'name' => 'My Dollars',
101-
'slug' => 'dollar',
80+
'meta' => ['currency' => 'USD'],
10281
]);
10382

10483
$rub = $user->createWallet([
105-
'name' => 'My Rub',
106-
'slug' => 'ruble',
84+
'name' => 'My Ruble',
85+
'meta' => ['currency' => 'RUB'],
10786
]);
10887
```
10988

docs/gift.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ class Item extends Model implements Product
4848
'description' => 'Purchase of Product #' . $this->id,
4949
];
5050
}
51-
52-
public function getUniqueId(): string
53-
{
54-
return (string)$this->getKey();
55-
}
5651
}
5752
```
5853

docs/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
ga: 'UA-98195013-2',
2020
cozyHouse: '3|T2LasA1LiSwMjenKkhwzCk7XeGmRqBkDtCD5qq0HszCRXLvewt85vto8B2sayMDeEcH79Xd6OO1cJaVv',
2121
loadSidebar: true,
22-
loadNavbar: true,
2322
relativePath: true,
2423
}
2524
</script>

0 commit comments

Comments
 (0)