Skip to content

Commit 8d84486

Browse files
committed
notification get* rewritten. TODO refactor tests
1 parent 7604b10 commit 8d84486

1 file changed

Lines changed: 45 additions & 22 deletions

File tree

lib/Hypercharge/PaymentNotification.php

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
11
<?php
22
namespace Hypercharge;
3-
3+
/**
4+
* PaymentNotifaction itself has a minimal set of fields.
5+
* Payment, Transaction and Schedule details can be fetched from hypercharge server with
6+
* <pre>
7+
* $payment = $notification->getPayment();
8+
* $transaction = $notification->getTransaction();
9+
* $schedule = $notification->getSchedule();
10+
* </pre>
11+
*
12+
* PaymentNotification fields.
13+
* You won't need to access them directly in most cases.
14+
*
15+
* Payment fields:
16+
* <pre>
17+
* notification_type
18+
* payment_unique_id
19+
* payment_transaction_id
20+
* payment_status
21+
* </pre>
22+
*
23+
* If the Payment has a Transaction:
24+
* <pre>
25+
* payment_transaction_transaction_type
26+
* payment_transaction_unique_id
27+
* payment_transaction_channel_token
28+
* </pre>
29+
*
30+
* If the Payment has a Schedule:
31+
* <pre>
32+
* schedule_unique_id
33+
* schedule_end_date
34+
* </pre>
35+
*/
436
class PaymentNotification implements INotification {
537

638
private $_verified = false;
@@ -11,16 +43,11 @@ function __construct($p) {
1143
}
1244

1345
/**
14-
* convinience method
15-
* @return stdClass fields: type, unique_id, transaction_id, status
46+
* fetch all Payment details from hypercharge server
47+
* @return Hypercharge\Payment
1648
*/
1749
function getPayment() {
18-
$o = new \stdClass();
19-
$o->type = $this->notification_type;
20-
$o->unique_id = $this->payment_unique_id;
21-
$o->transaction_id = $this->payment_transaction_id;
22-
$o->status = $this->payment_status;
23-
return $o;
50+
return Payment::find($this->payment_unique_id);
2451
}
2552

2653
/**
@@ -33,16 +60,13 @@ function hasTransaction() {
3360
}
3461

3562
/**
36-
* convinience method
37-
* @return stdClass fields: transaction_type, unique_id, channel_token
63+
* fetch all Transaction details from hypercharge server.
64+
* @return Hypercharge\Transaction null if Notification has no Transaction
3865
*/
3966
function getTransaction() {
4067
if(!$this->hasTransaction()) return null;
41-
$o = new \stdClass();
42-
$o->transaction_type = $this->payment_transaction_transaction_type;
43-
$o->unique_id = $this->payment_transaction_unique_id;
44-
$o->channel_token = $this->payment_transaction_channel_token;
45-
return $o;
68+
69+
return Transaction::find($this->payment_transaction_channel_token, $this->payment_transaction_unique_id);
4670
}
4771

4872
/**
@@ -53,15 +77,13 @@ function hasSchedule() {
5377
}
5478

5579
/**
56-
* convinience method
57-
* @return stdClass fields: unique_id, end_date
80+
* fetch all Schedule details from hypercharge server.
81+
* @return Hypercharge\Schedule null if Notification has no Schedule
5882
*/
5983
function getSchedule() {
6084
if(!$this->hasSchedule()) return null;
61-
$o = new \stdClass();
62-
$o->unique_id = $this->schedule_unique_id;
63-
$o->end_date = $this->schedule_end_date;
64-
return $o;
85+
86+
return Schedule::find($this->schedule_unique_id);
6587
}
6688

6789
/**
@@ -72,6 +94,7 @@ public function isVerified() {
7294
}
7395

7496
/**
97+
* @deprecated use $payment = $notification->getPayment(); $payment->isApproved()
7598
* checks if Payment.status == 'approved'
7699
* @return boolean
77100
*/

0 commit comments

Comments
 (0)