← All changes
|
src/Framework/PaymentGateways/Controllers/GatewaySubscriptionController.php
+18
-4
2.30.0
→
4.16.9
View file →
| @@ -6,8 +6,9 @@ | ||
| 6 | 6 | use Give\Framework\Exceptions\Primitives\Exception; |
| 7 | 7 | use Give\Framework\FieldsAPI\Exceptions\TypeNotSupported; |
| 8 | 8 | use Give\Framework\PaymentGateways\Actions\HandleGatewaySubscriptionCommand; |
| 9 | 9 | use Give\Framework\PaymentGateways\Commands\GatewayCommand; |
| 10 | +use Give\Framework\PaymentGateways\Exceptions\PaymentGatewayException; | |
| 10 | 11 | use Give\Framework\PaymentGateways\Log\PaymentGatewayLog; |
| 11 | 12 | use Give\Framework\PaymentGateways\PaymentGateway; |
| 12 | 13 | use Give\Framework\PaymentGateways\Traits\HandleHttpResponses; |
| 13 | 14 | use Give\Subscriptions\Models\Subscription; |
| @@ -32,27 +33,40 @@ | ||
| 32 | 33 | $this->gateway = $gateway; |
| 33 | 34 | } |
| 34 | 35 | |
| 35 | 36 | /** |
| 37 | + * @since 3.0.0 Catch and handle errors from the gateway upstream | |
| 36 | 38 | * @since 2.27.0 |
| 39 | + * | |
| 40 | + * @throws Exception|TypeNotSupported|PaymentGatewayException | |
| 37 | 41 | */ |
| 38 | 42 | public function create(Donation $donation, Subscription $subscription, array $gatewayData = []) |
| 39 | 43 | { |
| 44 | + $command = $this->gateway->createSubscription($donation, $subscription, $gatewayData); | |
| 45 | + | |
| 46 | + $this->handleGatewayCommand($command, $donation, $subscription); | |
| 47 | + } | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * @since 2.33.0 | |
| 51 | + */ | |
| 52 | + public function synchronizeSubscription(Subscription $subscription) | |
| 53 | + { | |
| 40 | 54 | try { |
| 41 | - $command = $this->gateway->createSubscription($donation, $subscription, $gatewayData); | |
| 42 | - $this->handleGatewayCommand($command, $donation, $subscription); | |
| 55 | + $command = $this->gateway->synchronizeSubscription($subscription); | |
| 56 | + $this->handleGatewayCommand($command, $subscription->initialDonation(), $subscription); | |
| 43 | 57 | } catch (\Exception $exception) { |
| 44 | 58 | PaymentGatewayLog::error( |
| 45 | 59 | $exception->getMessage(), |
| 46 | 60 | [ |
| 47 | 61 | 'Payment Gateway' => $this->gateway::id(), |
| 48 | - 'Donation' => $donation->toArray(), | |
| 62 | + 'Donation' => $subscription->initialDonation()->toArray(), | |
| 49 | 63 | 'Subscription' => $subscription->toArray(), |
| 50 | 64 | ] |
| 51 | 65 | ); |
| 52 | 66 | |
| 53 | 67 | $message = __( |
| 54 | - 'An unexpected error occurred while processing the subscription. Please try again or contact the site administrator.', | |
| 68 | + 'An unexpected error occurred while synchronizing the subscription. Please try again or contact the site administrator.', | |
| 55 | 69 | 'give' |
| 56 | 70 | ); |
| 57 | 71 | |
| 58 | 72 | $this->handleExceptionResponse($exception, $message); |