Skip to content

Commit c6afda8

Browse files
committed
feat: transaction id
1 parent 6d963dc commit c6afda8

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

src/Gateway.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Omnipay\Common\AbstractGateway;
66
use Omnipay\Common\Message\AbstractRequest;
7+
use Omnipay\Common\Message\NotificationInterface;
78
use Omnipay\Common\Message\RequestInterface;
89
use Omnipay\MyPay\Message\AcceptNotificationRequest;
910
use Omnipay\MyPay\Message\CompletePurchaseRequest;
@@ -43,7 +44,8 @@ public function getDefaultParameters()
4344
}
4445

4546
/**
46-
* @return AbstractRequest
47+
* @param array $options
48+
* @return RequestInterface
4749
*/
4850
public function purchase(array $options = [])
4951
{
@@ -52,7 +54,7 @@ public function purchase(array $options = [])
5254

5355
/**
5456
* @param array $options
55-
* @return AbstractRequest
57+
* @return RequestInterface
5658
*/
5759
public function completePurchase(array $options = [])
5860
{
@@ -61,13 +63,17 @@ public function completePurchase(array $options = [])
6163

6264
/**
6365
* @param array $options
64-
* @return AbstractRequest
66+
* @return RequestInterface
6567
*/
6668
public function acceptNotification(array $options = [])
6769
{
6870
return $this->createRequest(AcceptNotificationRequest::class, $options);
6971
}
7072

73+
/**
74+
* @param array $options
75+
* @return RequestInterface
76+
*/
7177
public function fetchTransaction(array $options = [])
7278
{
7379
return $this->createRequest(FetchTransactionRequest::class, $options);

src/Message/CompletePurchaseResponse.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public function getCode()
3737
return $this->data['prc'];
3838
}
3939

40+
public function getTransactionId()
41+
{
42+
return $this->data['order_id'];
43+
}
44+
4045
/**
4146
* Gateway Reference.
4247
*

src/Message/PurchaseRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ private function appendItems(array $data)
366366
$items = $this->getItems();
367367
$data['item'] = count($items);
368368
foreach ($items as $index => $item) {
369-
$data['i_'.$index.'_id'] = $item instanceof Item ? $item->getId() : '';
369+
$data['i_'.$index.'_id'] = $item instanceof Item ? $item->getId() : md5($item->getName());
370370
$data['i_'.$index.'_name'] = $item->getName();
371371
$data['i_'.$index.'_cost'] = $item->getPrice();
372372
$data['i_'.$index.'_amount'] = $item->getQuantity();

tests/GatewayTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public function test_complete_purchase()
120120
self::assertTrue($response->isSuccessful());
121121
self::assertEquals('250', $response->getCode());
122122
self::assertEquals('付款完成', $response->getMessage());
123+
self::assertEquals('d5jUed1tkQ9cDaD1', $response->getTransactionId());
123124
self::assertEquals('86579', $response->getTransactionReference());
124125
}
125126

@@ -174,6 +175,7 @@ public function test_fetch_transaction()
174175
self::assertTrue($response->isSuccessful());
175176
self::assertEquals('250', $response->getCode());
176177
self::assertEquals('付款完成', $response->getMessage());
178+
self::assertEquals('d5jUed1tkQ9cDaD1', $response->getTransactionId());
177179
self::assertEquals('86579', $response->getTransactionReference());
178180
}
179181
}

tests/Message/CompletePurchaseResponseTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function test_complete_purchase_success()
4646
self::assertTrue($response->isSuccessful());
4747
self::assertEquals('250', $response->getCode());
4848
self::assertEquals('付款完成', $response->getMessage());
49+
self::assertEquals('d5jUed1tkQ9cDaD1', $response->getTransactionId());
4950
self::assertEquals('86579', $response->getTransactionReference());
5051
}
5152
}

0 commit comments

Comments
 (0)