1: <?php
2:
3: namespace mcfedr\Paypal\Notifications;
4:
5: use mcfedr\Paypal\Authentication;
6: use mcfedr\Paypal\Exceptions\NotificationBusinessInvalidException;
7: use mcfedr\Paypal\Settings;
8:
9: class AdaptivePaymentNotification extends PaymentNotification {
10:
11: /**
12: * Status of Payment
13: * @var string
14: * The status of the payment. Possible values are:
15: * CREATED – The payment request was received; funds will be transferred once the payment is approved
16: * COMPLETED – The payment was successful
17: * INCOMPLETE – Some transfers succeeded and some failed for a parallel payment or, for a delayed chained payment, secondary receivers have not been paid
18: * ERROR – The payment failed and all attempted transfers failed or all completed transfers were successfully reversed
19: * REVERSALERROR – One or more transfers failed when attempting to reverse a payment
20: * PROCESSING – The payment is in progress
21: * PENDING – The payment is awaiting processing
22: */
23: public $status;
24:
25: /**
26: * Whether the Pay API is used with or without the SetPaymentOptions and ExecutePayment API operations. Possible values are:
27: * PAY – If you are not using the SetPaymentOptions and ExecutePayment API operations
28: * CREATE – If you are using the SetPaymentOptions and ExecutePayment API operations
29: * @var string
30: */
31: public $actionType;
32:
33: /**
34: * Whether the payment request specified to reverse parallel payments if an error occurs. Possible values are:
35: * true – Each parallel payment is reversed if an error occurs
36: * false – Only incomplete payments are reversed (default)
37: * @var bool
38: */
39: public $reverseAllParallelPaymentsOnError;
40:
41: /**
42: * The pay key that identifies this payment.
43: * This is a token that is assigned by the Pay API after a PayRequest message
44: * is received and can be used in other Adaptive Payments APIs as well
45: * as the cancelURL and returnURL to identify this payment.
46: * The pay key is valid for 3 hours.
47: * @var string
48: */
49: public $payKey;
50:
51: /**
52: * The payer of PayPal fees. Possible values are:
53: * SENDER – Sender pays all fees (for personal, implicit simple/parallel payments; do not use for chained or unilateral payments)
54: * PRIMARYRECEIVER – Primary receiver pays all fees (chained payments only)
55: * EACHRECEIVER – Each receiver pays their own fee (default, personal and unilateral payments)
56: * SECONDARYONLY – Secondary receivers pay all fees (use only for chained payments with one secondary receiver)
57: * @var string
58: */
59: public $feesPayer;
60:
61: /**
62: * The preapproval key returned after a PreapprovalRequest,
63: * or the preapproval key that identifies the preapproval key sent with a PayRequest.
64: * @var string
65: */
66: public $preapprovalKey;
67:
68: /**
69: * Whether this transaction is a chargeback, partial, or reversal. Possible values are:
70: * Chargeback Settlement – Transaction is a chargeback
71: * Admin reversal – Transaction was reversed by PayPal administrators
72: * Refund – Transaction was partially or fully refunded
73: * @var string
74: */
75: public $reasonCode;
76:
77: /**
78: * The tracking ID that was specified for this payment in the PaymentDetailsRequest message.
79: * @var string
80: */
81: public $trackingId;
82:
83: public function __construct($vars) {
84: parent::__construct($vars);
85: $this->type = static::ADAPTIVE;
86:
87: if (isset($vars['transaction_type'])) {
88: $this->transactionType = $vars['transaction_type'];
89: }
90:
91: if (isset($vars['status'])) {
92: $this->status = $vars['status'];
93: }
94:
95: if (isset($vars['payment_request_date'])) {
96: $this->date = new \DateTime($vars['payment_request_date']);
97: }
98:
99: if (isset($vars['action_type'])) {
100: $this->actionType = $vars['action_type'];
101: }
102:
103: if (isset($vars['pay_key'])) {
104: $this->payKey = $vars['pay_key'];
105: }
106:
107: if (isset($vars['fees_payer'])) {
108: $this->feesPayer = $vars['fees_payer'];
109: }
110:
111: if (isset($vars['trackingId'])) {
112: $this->invoiceId = $vars['trackingId'];
113: }
114:
115: if (isset($vars['preapproval_key'])) {
116: $this->preapprovalKey = $vars['preapproval_key'];
117: }
118:
119: if (isset($vars['reason_code'])) {
120: $this->reasonCode = $vars['reason_code'];
121: }
122:
123: $this->reverseAllParallelPaymentsOnError = isset($vars['reverse_all_parallel_payments_on_error']) && $vars['reverse_all_parallel_payments_on_error'] == 'true';
124: }
125:
126: /**
127: * Check that the notification matches the expected business
128: *
129: * @param Authentication $authentication
130: * @throws NotificationBusinessInvalidException
131: * @return bool
132: */
133: protected function isBusinessCorrect(Authentication $authentication) {
134: if ($this->sandbox != $authentication->isSandbox()) {
135: throw new NotificationBusinessInvalidException($this);
136: }
137: return true;
138: }
139:
140: /**
141: * Check the correct currency was used
142: *
143: * @param Settings $settings
144: * @return bool
145: */
146: protected function isCurrencyCorrect(Settings $settings) {
147: return true;
148: }
149: }
150: