Skip to content

Commit b802a59

Browse files
authored
Merge pull request #1 from shabayekdes/develop
Set order total amount when add items
2 parents 47a1b8f + 06288b3 commit b802a59

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Release Notes
2+
3+
## [Unreleased](https://github.com/shabayekdes/laravel-payment/compare/main...develop)
4+
5+
6+
## [v0.5 (2022-01-07)](https://github.com/shabayekdes/laravel-payment/compare/v0.4.1...develop)
7+
8+
### Changed
9+
- Set order total amount when add items ([#5750](https://github.com/shabayekdes/laravel-payment/pull/1))

src/Drivers/Method.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ abstract protected function setCredentials($credentials);
6565
/**
6666
* Set the amount of transaction.
6767
*
68+
* @deprecated v0.5
69+
*
6870
* @param $amount
6971
* @return $this
7072
* @throws \Exception
@@ -182,6 +184,7 @@ public function address($address)
182184
public function items(array $item)
183185
{
184186
$this->items[] = $item;
187+
$this->amount += $item['amount_cents'];
185188

186189
return $this;
187190
}

src/Drivers/PaymobMethod.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private function paymentKeyRequest($token, $orderPayId)
182182
"country" => "EG",
183183
],
184184
];
185-
185+
186186
$response = Http::post("{$this->url}acceptance/payment_keys", $postData);
187187

188188
$result = $response->json();
@@ -311,7 +311,7 @@ private function getOrderData($id)
311311
try {
312312
$token = $this->getAuthenticationToken();
313313
$response = Http::withToken($token)->get("{$this->url}acceptance/transactions/{$id}");
314-
314+
315315
$result = $response->json();
316316

317317
if ($response->ok() && isset($result['success']) && $result['success'] === true) {

tests/Unit/PaymentManagerTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,24 @@ public function a_payment_facade_invalid_exception_if_method_not_found(): void
5959
$method_id = 0;
6060
$payment = Payment::store($method_id);
6161
}
62+
/** @test */
63+
public function it_can_set_amount_when_add_to_items()
64+
{
65+
$payment = Payment::store(2);
66+
$items = [
67+
"name" => "ASC1515",
68+
"amount_cents" => 500000,
69+
"description" => "Smart Watch",
70+
"quantity" => "1"
71+
];
72+
$payment->items($items);
73+
74+
$reflector = new \ReflectionClass(PaymobMethod::class);
75+
$property = $reflector->getProperty('amount');
76+
$property->setAccessible(true);
77+
78+
$amount = $property->getValue($payment);
79+
80+
$this->assertEquals($items['amount_cents'], $amount);
81+
}
6282
}

0 commit comments

Comments
 (0)