PaymentAbandonedHandler.php
4 years ago
PaymentCompleteHandler.php
4 years ago
PaymentHandler.php
4 years ago
PaymentProcessingHandler.php
4 years ago
PaymentRefundedHandler.php
4 years ago
RedirectOffsiteHandler.php
4 years ago
RespondToBrowserHandler.php
4 years ago
SubscriptionCompleteHandler.php
4 years ago
SubscriptionCompleteHandler.php
60 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\PaymentGateways\CommandHandlers; |
| 4 | |
| 5 | use Give\Framework\PaymentGateways\Commands\SubscriptionComplete; |
| 6 | use Give_Subscription; |
| 7 | use Give_Subscriptions_DB; |
| 8 | |
| 9 | class SubscriptionCompleteHandler { |
| 10 | /** |
| 11 | * @since 2.18.0 |
| 12 | * |
| 13 | * @param SubscriptionComplete $subscriptionComplete |
| 14 | * @param int $subscriptionId |
| 15 | * @param int $donationId |
| 16 | * @return void |
| 17 | */ |
| 18 | public function __invoke(SubscriptionComplete $subscriptionComplete, $subscriptionId, $donationId) |
| 19 | { |
| 20 | give_update_payment_status($donationId); |
| 21 | give_set_payment_transaction_id($donationId, $subscriptionComplete->gatewayTransactionId); |
| 22 | |
| 23 | if (function_exists('give_recurring_update_subscription_status') && class_exists('Give_Subscriptions_DB')) { |
| 24 | give_recurring_update_subscription_status($subscriptionId, 'active'); |
| 25 | |
| 26 | $subscription = $this->getSubscription($subscriptionId); |
| 27 | |
| 28 | $subscription->update([ |
| 29 | 'profile_id' => $subscriptionComplete->gatewaySubscriptionId, |
| 30 | 'transaction_id' => $subscriptionComplete->gatewayTransactionId |
| 31 | ]); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @since 2.18.0 |
| 37 | * |
| 38 | * @return Give_Subscriptions_DB |
| 39 | */ |
| 40 | private function subscriptions() |
| 41 | { |
| 42 | /** |
| 43 | * @var Give_Subscriptions_DB $subscriptions |
| 44 | */ |
| 45 | return give(Give_Subscriptions_DB::class); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @since 2.18.0 |
| 50 | * |
| 51 | * @param int $subscriptionId |
| 52 | * |
| 53 | * @return Give_Subscription |
| 54 | */ |
| 55 | private function getSubscription($subscriptionId) |
| 56 | { |
| 57 | return current($this->subscriptions()->get_subscriptions(['id' => $subscriptionId])); |
| 58 | } |
| 59 | } |
| 60 |