This repository has been archived by the owner on Oct 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Update recurring support for PayPal Donations (#153)
- Loading branch information
Showing
4 changed files
with
214 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/NextGen/Gateways/PayPalCommerce/PayPalCommerceSubscriptionModule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Give\NextGen\Gateways\PayPalCommerce; | ||
|
||
use Give\Donations\Models\Donation; | ||
use Give\Framework\PaymentGateways\Commands\GatewayCommand; | ||
use Give\Framework\PaymentGateways\Commands\SubscriptionProcessing; | ||
use Give\Framework\PaymentGateways\Exceptions\PaymentGatewayException; | ||
use Give\Framework\PaymentGateways\SubscriptionModule; | ||
use Give\Subscriptions\Models\Subscription; | ||
use Give\Subscriptions\ValueObjects\SubscriptionStatus; | ||
use GiveRecurring\PaymentGateways\PayPalCommerce\Repositories\Subscription as SubscriptionRepository; | ||
|
||
class PayPalCommerceSubscriptionModule extends SubscriptionModule | ||
{ | ||
/** | ||
* @unreleased | ||
*/ | ||
public function createSubscription( | ||
Donation $donation, | ||
Subscription $subscription, | ||
$gatewayData = null | ||
): GatewayCommand { | ||
|
||
$subscriptionId = $gatewayData['payPalSubscriptionId']; | ||
|
||
return new SubscriptionProcessing($subscriptionId); | ||
} | ||
|
||
public function cancelSubscription(Subscription $subscription) | ||
{ | ||
try { | ||
give(SubscriptionRepository::class) | ||
->updateStatus($subscription->gatewaySubscriptionId, 'cancel'); | ||
|
||
$subscription->status = SubscriptionStatus::CANCELLED(); | ||
$subscription->save(); | ||
} catch (\Exception $exception) { | ||
throw new PaymentGatewayException( | ||
sprintf('Unable to cancel subscription with PayPal. %s', $exception->getMessage()), | ||
$exception->getCode(), | ||
$exception | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.