| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Modules\PaymentMethods\Core; |
| 4 |
|
| 5 |
use FluentCart\App\Models\Subscription; |
| 6 |
|
| 7 |
abstract class AbstractSubscriptionModule |
| 8 |
{ |
| 9 |
/** |
| 10 |
* @throws \Exception |
| 11 |
*/ |
| 12 |
public function fetchSubscription($data, $order, $subscription) |
| 13 |
{ |
| 14 |
throw new \Exception(esc_html__('Subscription fetching not available for this method!', 'fluent-cart'), 404); |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* @throws \Exception |
| 19 |
*/ |
| 20 |
public function cardUpdate($data, $subscriptionId) |
| 21 |
{ |
| 22 |
throw new \Exception(esc_html__('No valid payment method to update!', 'fluent-cart'), 404); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* @throws \Exception |
| 27 |
*/ |
| 28 |
public function switchPaymentMethod($data, $subscriptionId) |
| 29 |
{ |
| 30 |
throw new \Exception(esc_html__('No valid payment method to switch!', 'fluent-cart'), 404); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* @throws \Exception |
| 35 |
*/ |
| 36 |
public function reactivateSubscription($data, $subscriptionId) |
| 37 |
{ |
| 38 |
throw new \Exception(esc_html__('No valid payment method to reactivate!', 'fluent-cart'), 404); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* @throws \Exception |
| 43 |
*/ |
| 44 |
public function pauseSubscription($data, $order, $subscription) |
| 45 |
{ |
| 46 |
throw new \Exception(esc_html__('No valid payment method to pause!', 'fluent-cart'), 404); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* @throws \Exception |
| 51 |
*/ |
| 52 |
public function resumeSubscription($data, $order, $subscription) |
| 53 |
{ |
| 54 |
throw new \Exception(esc_html__('No valid payment method to resume!', 'fluent-cart'), 404); |
| 55 |
} |
| 56 |
|
| 57 |
public function cancel($vendorSubscriptionId, $args = []) |
| 58 |
{ |
| 59 |
return new \WP_Error( |
| 60 |
'not_implemented', |
| 61 |
esc_html__('Cancel subscription is not implemented for this payment method.', 'fluent-cart') |
| 62 |
); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* @throws \Exception |
| 67 |
*/ |
| 68 |
public function cancelSubscription($data, $order, $subscription) |
| 69 |
{ |
| 70 |
throw new \Exception(esc_html__('No valid payment method to cancel!', 'fluent-cart'), 404); |
| 71 |
} |
| 72 |
|
| 73 |
public function cancelOnPlanChange($vendorSubscriptionId, $parentOrderId, $subscriptionId, $reason) |
| 74 |
{ |
| 75 |
// cancel the subscription on the vendor side, implement on the child class |
| 76 |
} |
| 77 |
|
| 78 |
public function cancelAutoRenew($subscription) |
| 79 |
{ |
| 80 |
// cancel the subscription on the vendor side, implement on the child class |
| 81 |
} |
| 82 |
|
| 83 |
public function cancelOnSwitchPaymentMethod($currentVendorSubscriptionId, $parentOrderId, $vendorSubscriptionId, $newPaymentMethod, $reason) |
| 84 |
{ |
| 85 |
// cancel the subscription on the vendor side, implement on the child class |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Pull the subscription's remote state and repair the local rows to match. |
| 90 |
* |
| 91 |
* Implementations may declare extra OPTIONAL parameters for pre-fetched |
| 92 |
* vendor payloads (e.g. PayPal accepts the already-fetched subscription and |
| 93 |
* transaction list so a webhook costs one remote pull). Callers typed |
| 94 |
* against this base class must pass only the subscription model. |
| 95 |
* |
| 96 |
* @param Subscription $subscriptionModel |
| 97 |
* @return Subscription|\WP_Error |
| 98 |
*/ |
| 99 |
public function reSyncSubscriptionFromRemote(Subscription $subscriptionModel) |
| 100 |
{ |
| 101 |
return new \WP_Error( |
| 102 |
'not_implemented', |
| 103 |
esc_html__('Re-sync subscription from remote is not implemented for this payment method.', 'fluent-cart') |
| 104 |
); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Read-only lookup of a candidate vendor subscription id, used by the admin |
| 109 |
* "Edit Vendor IDs" verify action before the id is saved. Writes nothing. |
| 110 |
* Only reached when the gateway declares the verify_vendor_ids feature. |
| 111 |
* |
| 112 |
* $args carries both candidate ids because some gateways nest the |
| 113 |
* subscription under its customer. |
| 114 |
* |
| 115 |
* @param array $args vendor_subscription_id, vendor_customer_id |
| 116 |
* @return array|\WP_Error normalized id/status/amount/currency/customer_id/next_billing_date |
| 117 |
*/ |
| 118 |
public function verifyVendorSubscription(array $args, $mode = 'current') |
| 119 |
{ |
| 120 |
return new \WP_Error( |
| 121 |
'not_implemented', |
| 122 |
esc_html__('Vendor subscription lookup is not implemented for this payment method.', 'fluent-cart') |
| 123 |
); |
| 124 |
} |
| 125 |
} |
| 126 |
|