7
7
use Bitpay \BPCheckout \Model \BitpayInvoiceRepository ;
8
8
use Bitpay \BPCheckout \Model \Client as ClientFactory ;
9
9
use Bitpay \BPCheckout \Model \Ipn \IpnNotificationSender ;
10
+ use BitPaySDK \Model \Invoice \Buyer ;
10
11
use PHPUnit \Framework \TestCase ;
11
12
12
13
class IpnNotificationSenderTest extends TestCase
13
14
{
14
15
private const EXISTING_ORDER_ID = '11 ' ;
15
16
private const NON_EXISTING_ORDER_ID = '121312321 ' ;
16
17
private const INVOICE_ID = '123 ' ;
18
+ private const INVOICE_TOKEN = 'token ' ;
17
19
18
20
public function testSendIpnNotification (): void
19
21
{
@@ -23,8 +25,10 @@ public function testSendIpnNotification(): void
23
25
$ bitpayInvoiceRepository ->method ('getByOrderId ' )->with (self ::EXISTING_ORDER_ID )
24
26
->willReturn (['invoice_id ' => self ::INVOICE_ID ]);
25
27
$ clientFactory ->method ('initialize ' )->willReturn ($ client );
28
+ $ invoice = $ this ->prepareInvoice ();
29
+ $ client ->expects ($ this ->once ())->method ('getInvoice ' )->willReturn ($ invoice );
26
30
27
- $ client ->expects (self ::once ())->method ('requestInvoiceNotification ' )->with (self ::INVOICE_ID );
31
+ $ client ->expects (self ::once ())->method ('requestInvoiceNotification ' )->with (self ::INVOICE_ID , self :: INVOICE_TOKEN );
28
32
29
33
$ testedClass = $ this ->getTestedClass ($ clientFactory , $ bitpayInvoiceRepository );
30
34
$ testedClass ->execute (self ::EXISTING_ORDER_ID );
@@ -39,13 +43,30 @@ public function testIncorrectSendIpnNotification(): void
39
43
->willReturn (null );
40
44
$ clientFactory ->method ('initialize ' )->willReturn ($ client );
41
45
42
- $ client ->expects (self ::never ())->method ('requestInvoiceNotification ' )->with (self ::INVOICE_ID );
46
+ $ client ->expects (self ::never ())->method ('requestInvoiceNotification ' )->with (self ::INVOICE_ID , self :: INVOICE_TOKEN );
43
47
$ this ->expectException (\RuntimeException::class);
44
48
45
49
$ testedClass = $ this ->getTestedClass ($ clientFactory , $ bitpayInvoiceRepository );
46
50
$ testedClass ->execute (self ::NON_EXISTING_ORDER_ID );
47
51
}
48
52
53
+ /**
54
+ * @return \BitPaySDK\Model\Invoice\Invoice
55
+ */
56
+ private function prepareInvoice (): \BitPaySDK \Model \Invoice \Invoice
57
+ {
58
+ $ invoice = new \BitPaySDK \Model \Invoice \Invoice (12.00 , 'USD ' );
59
+ $ invoice ->setAmountPaid (1232132 );
60
+ $ invoice ->setToken (self ::INVOICE_TOKEN );
61
+ $ buyer = new Buyer ();
62
+ $ buyer ->setName ('test ' );
63
+ $ buyer->
setEmail (
'[email protected] ' );
64
+ $ buyer ->setAddress1 ('12 test road ' );
65
+ $ invoice ->setBuyer ($ buyer );
66
+
67
+ return $ invoice ;
68
+ }
69
+
49
70
private function getTestedClass (ClientFactory $ clientFactory , BitpayInvoiceRepository $ bitpayInvoiceRepository )
50
71
{
51
72
return new IpnNotificationSender ($ clientFactory , $ bitpayInvoiceRepository );
0 commit comments