← All changes
|
src/Framework/PaymentGateways/Webhooks/WebhookEvents.php
+122
-26
4.15.0
→
4.18.0
View file →
| @@ -24,95 +24,180 @@ | ||
| 24 | 24 | $this->gatewayId = $gatewayId; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | + * @since 4.16.0 Add $donationId to support gateways that only receive the transaction ID via webhook (e.g. PayFast). | |
| 28 | 29 | * @since 4.5.0 |
| 29 | 30 | */ |
| 30 | 31 | public function donationAbandoned( |
| 31 | 32 | string $gatewayTransactionId, |
| 32 | 33 | string $message = '', |
| 33 | - $skipRecurringDonations = false | |
| 34 | + bool $skipRecurringDonations = false, | |
| 35 | + int $donationId = 0 | |
| 34 | 36 | ) { |
| 35 | - $this->setDonationStatus(DonationStatus::ABANDONED(), $gatewayTransactionId, $message, $skipRecurringDonations); | |
| 37 | + $this->setDonationStatus( | |
| 38 | + DonationStatus::ABANDONED(), | |
| 39 | + $gatewayTransactionId, | |
| 40 | + $message, | |
| 41 | + $skipRecurringDonations, | |
| 42 | + $donationId | |
| 43 | + ); | |
| 36 | 44 | } |
| 37 | 45 | |
| 38 | 46 | /** |
| 47 | + * @since 4.16.0 Add $donationId to support gateways that only receive the transaction ID via webhook (e.g. PayFast). | |
| 39 | 48 | * @since 4.5.0 |
| 40 | 49 | */ |
| 41 | 50 | public function donationCancelled( |
| 42 | 51 | string $gatewayTransactionId, |
| 43 | 52 | string $message = '', |
| 44 | - $skipRecurringDonations = false | |
| 53 | + bool $skipRecurringDonations = false, | |
| 54 | + int $donationId = 0 | |
| 45 | 55 | ) { |
| 46 | - $this->setDonationStatus(DonationStatus::CANCELLED(), $gatewayTransactionId, $message, $skipRecurringDonations); | |
| 56 | + $this->setDonationStatus( | |
| 57 | + DonationStatus::CANCELLED(), | |
| 58 | + $gatewayTransactionId, | |
| 59 | + $message, | |
| 60 | + $skipRecurringDonations, | |
| 61 | + $donationId | |
| 62 | + ); | |
| 47 | 63 | } |
| 48 | 64 | |
| 49 | 65 | /** |
| 66 | + * @since 4.16.0 Add $donationId to support gateways that only receive the transaction ID via webhook (e.g. PayFast). | |
| 50 | 67 | * @since 4.5.0 |
| 51 | 68 | */ |
| 52 | 69 | public function donationCompleted( |
| 53 | 70 | string $gatewayTransactionId, |
| 54 | 71 | string $message = '', |
| 55 | - $skipRecurringDonations = false | |
| 72 | + bool $skipRecurringDonations = false, | |
| 73 | + int $donationId = 0 | |
| 56 | 74 | ) { |
| 57 | - $this->setDonationStatus(DonationStatus::COMPLETE(), $gatewayTransactionId, $message, $skipRecurringDonations); | |
| 75 | + $this->setDonationStatus( | |
| 76 | + DonationStatus::COMPLETE(), | |
| 77 | + $gatewayTransactionId, | |
| 78 | + $message, | |
| 79 | + $skipRecurringDonations, | |
| 80 | + $donationId | |
| 81 | + ); | |
| 58 | 82 | } |
| 59 | 83 | |
| 60 | 84 | /** |
| 85 | + * @since 4.16.0 Add $donationId to support gateways that only receive the transaction ID via webhook (e.g. PayFast). | |
| 61 | 86 | * @since 4.5.0 |
| 62 | 87 | */ |
| 63 | - public function donationFailed(string $gatewayTransactionId, string $message = '', $skipRecurringDonations = false) | |
| 88 | + public function donationFailed( | |
| 89 | + string $gatewayTransactionId, | |
| 90 | + string $message = '', | |
| 91 | + bool $skipRecurringDonations = false, | |
| 92 | + int $donationId = 0 | |
| 93 | + ) | |
| 64 | 94 | { |
| 65 | - $this->setDonationStatus(DonationStatus::FAILED(), $gatewayTransactionId, $message, $skipRecurringDonations); | |
| 95 | + $this->setDonationStatus( | |
| 96 | + DonationStatus::FAILED(), | |
| 97 | + $gatewayTransactionId, | |
| 98 | + $message, | |
| 99 | + $skipRecurringDonations, | |
| 100 | + $donationId | |
| 101 | + ); | |
| 66 | 102 | } |
| 67 | 103 | |
| 68 | 104 | /** |
| 105 | + * @since 4.16.0 Add $donationId to support gateways that only receive the transaction ID via webhook (e.g. PayFast). | |
| 69 | 106 | * @since 4.5.0 |
| 70 | 107 | */ |
| 71 | - public function donationPending(string $gatewayTransactionId, string $message = '', $skipRecurringDonations = false) | |
| 108 | + public function donationPending( | |
| 109 | + string $gatewayTransactionId, | |
| 110 | + string $message = '', | |
| 111 | + bool $skipRecurringDonations = false, | |
| 112 | + int $donationId = 0 | |
| 113 | + ) | |
| 72 | 114 | { |
| 73 | - $this->setDonationStatus(DonationStatus::PENDING(), $gatewayTransactionId, $message, $skipRecurringDonations); | |
| 115 | + $this->setDonationStatus( | |
| 116 | + DonationStatus::PENDING(), | |
| 117 | + $gatewayTransactionId, | |
| 118 | + $message, | |
| 119 | + $skipRecurringDonations, | |
| 120 | + $donationId | |
| 121 | + ); | |
| 74 | 122 | } |
| 75 | 123 | |
| 76 | 124 | /** |
| 125 | + * @since 4.16.0 Add $donationId to support gateways that only receive the transaction ID via webhook (e.g. PayFast). | |
| 77 | 126 | * @since 4.5.0 |
| 78 | 127 | */ |
| 79 | 128 | public function donationPreapproval( |
| 80 | 129 | string $gatewayTransactionId, |
| 81 | 130 | string $message = '', |
| 82 | - $skipRecurringDonations = false | |
| 131 | + bool $skipRecurringDonations = false, | |
| 132 | + int $donationId = 0 | |
| 83 | 133 | ) { |
| 84 | - $this->setDonationStatus(DonationStatus::PREAPPROVAL(), $gatewayTransactionId, $message, | |
| 85 | - $skipRecurringDonations); | |
| 134 | + $this->setDonationStatus( | |
| 135 | + DonationStatus::PREAPPROVAL(), | |
| 136 | + $gatewayTransactionId, | |
| 137 | + $message, | |
| 138 | + $skipRecurringDonations, | |
| 139 | + $donationId | |
| 140 | + ); | |
| 86 | 141 | } |
| 87 | 142 | |
| 88 | 143 | /** |
| 144 | + * @since 4.16.0 Add $donationId to support gateways that only receive the transaction ID via webhook (e.g. PayFast). | |
| 89 | 145 | * @since 4.5.0 |
| 90 | 146 | */ |
| 91 | 147 | public function donationProcessing( |
| 92 | 148 | string $gatewayTransactionId, |
| 93 | 149 | string $message = '', |
| 94 | - $skipRecurringDonations = false | |
| 95 | - ) | |
| 96 | - { | |
| 97 | - $this->setDonationStatus(DonationStatus::PROCESSING(), $gatewayTransactionId, $message, | |
| 98 | - $skipRecurringDonations); | |
| 150 | + bool $skipRecurringDonations = false, | |
| 151 | + int $donationId = 0 | |
| 152 | + ) { | |
| 153 | + $this->setDonationStatus( | |
| 154 | + DonationStatus::PROCESSING(), | |
| 155 | + $gatewayTransactionId, | |
| 156 | + $message, | |
| 157 | + $skipRecurringDonations, | |
| 158 | + $donationId | |
| 159 | + ); | |
| 99 | 160 | } |
| 100 | 161 | |
| 101 | 162 | /** |
| 163 | + * @since 4.16.0 Add $donationId to support gateways that only receive the transaction ID via webhook (e.g. PayFast). | |
| 102 | 164 | * @since 4.5.0 |
| 103 | 165 | */ |
| 104 | - public function donationRefunded(string $gatewayTransactionId, string $message = '', $skipRecurringDonations = false) | |
| 166 | + public function donationRefunded( | |
| 167 | + string $gatewayTransactionId, | |
| 168 | + string $message = '', | |
| 169 | + bool $skipRecurringDonations = false, | |
| 170 | + int $donationId = 0 | |
| 171 | + ) | |
| 105 | 172 | { |
| 106 | - $this->setDonationStatus(DonationStatus::REFUNDED(), $gatewayTransactionId, $message, $skipRecurringDonations); | |
| 173 | + $this->setDonationStatus( | |
| 174 | + DonationStatus::REFUNDED(), | |
| 175 | + $gatewayTransactionId, | |
| 176 | + $message, | |
| 177 | + $skipRecurringDonations, | |
| 178 | + $donationId | |
| 179 | + ); | |
| 107 | 180 | } |
| 108 | 181 | |
| 109 | 182 | /** |
| 183 | + * @since 4.16.0 Add $donationId to support gateways that only receive the transaction ID via webhook (e.g. PayFast). | |
| 110 | 184 | * @since 4.5.0 |
| 111 | 185 | */ |
| 112 | - public function donationRevoked(string $gatewayTransactionId, string $message = '', $skipRecurringDonations = false) | |
| 186 | + public function donationRevoked( | |
| 187 | + string $gatewayTransactionId, | |
| 188 | + string $message = '', | |
| 189 | + bool $skipRecurringDonations = false, | |
| 190 | + int $donationId = 0 | |
| 191 | + ) | |
| 113 | 192 | { |
| 114 | - $this->setDonationStatus(DonationStatus::REVOKED(), $gatewayTransactionId, $message, $skipRecurringDonations); | |
| 193 | + $this->setDonationStatus( | |
| 194 | + DonationStatus::REVOKED(), | |
| 195 | + $gatewayTransactionId, | |
| 196 | + $message, | |
| 197 | + $skipRecurringDonations, | |
| 198 | + $donationId | |
| 199 | + ); | |
| 115 | 200 | } |
| 116 | 201 | |
| 117 | 202 | /** |
| 118 | 203 | * @since 4.5.0 |
| @@ -183,8 +268,9 @@ | ||
| 183 | 268 | $this->setSubscriptionStatus(SubscriptionStatus::SUSPENDED(), $gatewaySubscriptionId, $message); |
| 184 | 269 | } |
| 185 | 270 | |
| 186 | 271 | /** |
| 272 | + * @since 4.16.0 Add $donationId to support gateways that only receive the transaction ID via webhook (e.g. PayFast). | |
| 187 | 273 | * @since 4.5.0 |
| 188 | 274 | * |
| 189 | 275 | * @return int The webhook event ID. Zero if there was an error setting the event. |
| 190 | 276 | */ |
| @@ -192,12 +278,20 @@ | ||
| 192 | 278 | string $gatewayTransactionId, |
| 193 | 279 | string $message = '', |
| 194 | 280 | bool $setSubscriptionActive = true, |
| 195 | 281 | bool $setDonationComplete = true, |
| 196 | - string $gatewaySubscriptionId = '' | |
| 282 | + string $gatewaySubscriptionId = '', | |
| 283 | + int $donationId = 0 | |
| 197 | 284 | ): int { |
| 198 | 285 | $hook = sprintf('givewp_%s_webhook_event_subscription_first_donation', $this->gatewayId); |
| 199 | - $args = [$gatewayTransactionId, $message, $setSubscriptionActive, $setDonationComplete, $gatewaySubscriptionId]; | |
| 286 | + $args = [ | |
| 287 | + $gatewayTransactionId, | |
| 288 | + $message, | |
| 289 | + $setSubscriptionActive, | |
| 290 | + $setDonationComplete, | |
| 291 | + $gatewaySubscriptionId, | |
| 292 | + $donationId, | |
| 293 | + ]; | |
| 200 | 294 | $group = $this->getGroup(); |
| 201 | 295 | |
| 202 | 296 | return AsBackgroundJobs::enqueueAsyncAction($hook, $args, $group); |
| 203 | 297 | } |
| @@ -219,8 +313,9 @@ | ||
| 219 | 313 | return AsBackgroundJobs::enqueueAsyncAction($hook, $args, $group); |
| 220 | 314 | } |
| 221 | 315 | |
| 222 | 316 | /** |
| 317 | + * @since 4.16.0 Add $donationId to support gateways that only receive the transaction ID via webhook (e.g. PayFast). | |
| 223 | 318 | * @since 4.5.0 |
| 224 | 319 | * |
| 225 | 320 | * @return int The webhook event ID. Zero if there was an error setting the event. |
| 226 | 321 | */ |
| @@ -227,12 +322,13 @@ | ||
| 227 | 322 | protected function setDonationStatus( |
| 228 | 323 | DonationStatus $status, |
| 229 | 324 | string $gatewayTransactionId, |
| 230 | 325 | string $message = '', |
| 231 | - $skipRecurringDonations = false | |
| 326 | + bool $skipRecurringDonations = false, | |
| 327 | + int $donationId = 0 | |
| 232 | 328 | ): int { |
| 233 | 329 | $hook = sprintf('givewp_%s_webhook_event_donation_status_%s', $this->gatewayId, $status->getValue()); |
| 234 | - $args = [$gatewayTransactionId, $message, $skipRecurringDonations]; | |
| 330 | + $args = [$gatewayTransactionId, $message, $skipRecurringDonations, $donationId]; | |
| 235 | 331 | $group = $this->getGroup(); |
| 236 | 332 | |
| 237 | 333 | return AsBackgroundJobs::enqueueAsyncAction($hook, $args, $group); |
| 238 | 334 | } |