File tree Expand file tree Collapse file tree 3 files changed +56
-5
lines changed Expand file tree Collapse file tree 3 files changed +56
-5
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ class OrderBuilder
8
8
{
9
9
private string $ externalId = '' ;
10
10
private string $ currency = '' ;
11
- private int $ amount = 0 ;
11
+ private float $ amount = 0 ;
12
12
private string $ description = '' ;
13
13
private string $ brandName = '' ;
14
14
private string $ locale = 'es-AR ' ;
@@ -39,10 +39,10 @@ public function currency(string $currency): OrderBuilder
39
39
}
40
40
41
41
/**
42
- * @param int $amount
42
+ * @param float $amount
43
43
* @return OrderBuilder
44
44
*/
45
- public function amount (int $ amount ): OrderBuilder
45
+ public function amount (float $ amount ): OrderBuilder
46
46
{
47
47
$ this ->amount = $ amount ;
48
48
return $ this ;
@@ -107,7 +107,7 @@ public function make(): array
107
107
'custom_id ' => $ this ->externalId ,
108
108
'amount ' => [
109
109
'currency_code ' => $ this ->currency ,
110
- 'value ' => $ this ->amount ,
110
+ 'value ' => round ( $ this ->amount , 2 ) ,
111
111
],
112
112
'description ' => $ this ->description ,
113
113
'payment_options ' => [
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Tests ;
4
+
5
+ use PHPUnit \Framework \TestCase ;
6
+ use Puntodev \Payments \OrderBuilder ;
7
+
8
+ class OrderBuilderTest extends TestCase
9
+ {
10
+ /** @test */
11
+ public function create_order_with_int_amount ()
12
+ {
13
+ $ order = (new OrderBuilder ())
14
+ ->externalId ('31fe5538-8589-437d-8823-3b0574186a5f ' )
15
+ ->currency ('USD ' )
16
+ ->amount (23.206 )
17
+ ->description ('My custom product ' )
18
+ ->brandName ('My brand name ' )
19
+ ->returnUrl ('http://localhost:8080/return ' )
20
+ ->cancelUrl ('http://localhost:8080/cancel ' )
21
+ ->make ();
22
+
23
+ $ this ->assertEquals ([
24
+ 'intent ' => 'CAPTURE ' ,
25
+ 'purchase_units ' => [
26
+ [
27
+ 'custom_id ' => '31fe5538-8589-437d-8823-3b0574186a5f ' ,
28
+ 'amount ' => [
29
+ 'currency_code ' => 'USD ' ,
30
+ 'value ' => 23.21 ,
31
+ ],
32
+ 'description ' => 'My custom product ' ,
33
+ 'payment_options ' => [
34
+ 'allowed_payment_method ' => 'INSTANT_FUNDING_SOURCE '
35
+ ],
36
+ ]
37
+ ],
38
+ 'application_context ' => [
39
+ 'brand_name ' => 'My brand name ' ,
40
+ 'locale ' => 'es-AR ' ,
41
+ 'user_action ' => 'PAY_NOW ' ,
42
+ 'payment_method ' => [
43
+ 'payee_preferred ' => 'IMMEDIATE_PAYMENT_REQUIRED ' ,
44
+ ],
45
+ 'shipping_preference ' => 'NO_SHIPPING ' ,
46
+ 'return_url ' => 'http://localhost:8080/return ' ,
47
+ 'cancel_url ' => 'http://localhost:8080/cancel '
48
+ ],
49
+ ], $ order );
50
+ }
51
+ }
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ public function testCreateOrder()
46
46
$ order = (new OrderBuilder ())
47
47
->externalId ($ this ->faker ->uuid )
48
48
->currency ('USD ' )
49
- ->amount (23 )
49
+ ->amount (23.20 )
50
50
->description ('My custom product ' )
51
51
->brandName ('My brand name ' )
52
52
->returnUrl ('http://localhost:8080/return ' )
You can’t perform that action at this time.
0 commit comments