PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.5
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.5
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Modules / Payments / PaymentMethods / Stripe / PaymentManager.php

PaymentManager.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.5, at app/Modules/Payments/PaymentMethods/Stripe/PaymentManager.php

78 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Modules\Payments\PaymentMethods\Stripe;
4
5 use FluentForm\App\Models\Transaction;
6 use FluentForm\App\Modules\Payments\PaymentHelper;
7 use FluentForm\App\Modules\Payments\PaymentMethods\Stripe\API\ApiRequest;
8
9 if (!defined('ABSPATH')) {
10 exit; // Exit if accessed directly.
11 }
12
13 class PaymentManager
14 {
15 public function cancelSubscription($subscription, $scope = 'admin', $submission = false)
16 {
17 if(!$submission) {
18 $submission = fluentFormApi('submissions')->find($subscription->submission_id);
19 }
20
21 if(!$submission || $submission->payment_method != 'stripe') {
22 return new \WP_Error('method_mismatch', __('Failed to cancel this subscription', 'fluentform'));
23 }
24
25 // Get the first transaction to determine the payment mode
26 $lastTransaction = Transaction::where('subscription_id', $subscription->id)
27 ->where('payment_method', 'stripe')
28 ->orderBy('id', 'DESC')
29 ->first();
30
31 if(!$lastTransaction) {
32 return new \WP_Error('transaction_mismatch', __('Failed to cancel this subscription', 'fluentform'));
33 }
34
35 $vendorSubscriptionId = $subscription->vendor_subscription_id;
36
37 if(!$vendorSubscriptionId) {
38 return new \WP_Error('no_vendor_subscription_found', __('Failed to cancel this subscription', 'fluentform'));
39 }
40
41 $secretKey = StripeSettings::getSecretKey($submission->form_id);
42 ApiRequest::set_secret_key($secretKey);
43 $response = ApiRequest::request([], 'subscriptions/'.$vendorSubscriptionId, 'DELETE');
44
45 if(is_wp_error($response)) {
46 return $response;
47 }
48
49 PaymentHelper::recordSubscriptionCancelled($subscription, $response, [
50 'parent_source_id' => $submission->form_id,
51 'source_type' => 'submission_item',
52 'source_id' => $submission->id,
53 'component' => 'General',
54 'status' => 'info',
55 'title' => __('Subscription has been cancelled by ', 'fluentform') . $scope,
56 'description' => __('Subscription has been cancelled from ', 'fluentform') . $submission->payment_method
57 ]);
58
59 // It's a success so let's send a valid response
60 return $response;
61 }
62
63 public function refundTransaction($transaction, $scope = 'admin')
64 {
65
66 }
67
68 private function retrieveVendorSubscription($subscription)
69 {
70
71 }
72
73 private function retrieveVendorTransaction($transaction)
74 {
75
76 }
77 }
78