PluginProbe
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More / 2.2.0
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More v2.2.0
2.3.0 2.2.0 2.1.1 2.1.0 2.0.0 1.10.0 1.9.1 1.9.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 All 59 releases
storeengine / includes / admin / settings / payments.php

payments.php in StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More 2.2.0, at includes/admin/settings/payments.php

154 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace StoreEngine\Admin\Settings;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * @deprecated
11 */
12 class Payments {
13
14 /**
15 * @deprecated
16 */
17 public static function get_settings_saved_data() {
18 $settings = get_option( STOREENGINE_PAYMENTS_SETTINGS_NAME );
19 $settings = json_decode( $settings, true );
20 $settings = is_array( $settings ) ? $settings : [];
21
22 $parsed_settings = [];
23
24 $default_settings = self::get_settings_default_data();
25
26 foreach ( $settings as $setting ) {
27 if ( empty( $setting['title'] ) ) {
28 $setting['title'] = $default_settings[ $setting['type'] ]['title'] ?? '';
29 }
30
31 if ( empty( $setting['index'] ) ) {
32 $setting['index'] = $default_settings[ $setting['type'] ]['index'] ?? 0;
33 }
34
35 $parsed_settings[ $setting['type'] ] = $setting;
36 }
37
38
39 return array_values( $parsed_settings );
40 }
41
42 /**
43 * @deprecated
44 */
45 public static function get_settings_default_data() {
46 // @TODO make separate gateway class
47 return apply_filters( 'storeengine/admin/payments_settings_default_data', [
48 'bank_transfer' => [
49 'type' => 'bank_transfer',
50 'is_enabled' => false,
51 'title' => __( 'Bank Transfer', 'storeengine' ),
52 'description' => __( 'Take payments in person via BACS. More commonly known as direct bank/wire transfer.', 'storeengine' ),
53 'instructions' => __( 'Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order will not be shipped until the funds have cleared in our account.', 'storeengine' ),
54 'accounts' => [],
55 'index' => 0,
56 ],
57 'check_payment' => [
58 'type' => 'check_payment',
59 'is_enabled' => false,
60 'title' => __( 'Check Payment', 'storeengine' ),
61 'description' => __( 'Take payments in person via checks. This offline gateway can also be useful to test purchases.', 'storeengine' ),
62 'instructions' => __( 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.', 'storeengine' ),
63 'index' => 1,
64 ],
65 'cash_on_delivery' => [
66 'type' => 'cash_on_delivery',
67 'is_enabled' => false,
68 'title' => __( 'Cash on delivery', 'storeengine' ),
69 'description' => __( 'Have your customers pay with cash (or by other means) upon delivery.', 'storeengine' ),
70 'instructions' => __( 'Pay with cash upon delivery.', 'storeengine' ),
71 'index' => 2,
72 ],
73 'paypal' => [
74 'type' => 'paypal',
75 'title' => 'Paypal',
76 'description' => __( 'Accept PayPal, Pay Later and alternative payment types.', 'storeengine' ),
77 'instructions' => __( 'Continue with PayPal, Pay Later and alternative payment types.', 'storeengine' ),
78 'is_enabled' => false,
79 'is_enabled_sandbox' => false,
80 'sandbox_client_id' => '',
81 'sandbox_client_secret' => '',
82 'live_client_id' => '',
83 'live_client_secret' => '',
84 'index' => 3,
85 ],
86 'stripe' => [
87 'type' => 'stripe',
88 'title' => __( 'Stripe', 'storeengine' ),
89 'description' => __( 'Accept debit and credit cards in 135+ currencies, methods such as SEPA, and one-touch checkout with Apple Pay.', 'storeengine' ),
90 'is_enabled' => false,
91 'is_enabled_test_mode' => false,
92 'test_publishable_key' => '',
93 'test_secret_key' => '',
94 'live_publishable_key' => '',
95 'live_secret_key' => '',
96 'index' => 4,
97 ],
98 ] );
99 }
100
101 /**
102 * @deprecated
103 */
104 public static function save_settings( $form_data = false ) {
105 $default_data = self::get_settings_default_data();
106 $saved_data = self::get_settings_saved_data();
107 $settings_data = ! empty( $saved_data ) ? $saved_data : $default_data;
108
109 if ( $form_data && is_array( $form_data ) ) {
110 foreach ( $form_data as $form_data_item ) {
111 $type = $form_data_item['type'];
112 $found = false;
113 // Update the existing settings data
114 foreach ( $settings_data as &$existingItem ) {
115 if ( $existingItem['type'] === $type ) {
116 foreach ( $form_data_item as $key => $value ) {
117 if ( array_key_exists( $key, $existingItem ) ) {
118 $existingItem[ $key ] = $value;
119 }
120 }
121 $found = true;
122 break;
123 }
124 }
125 // If the type is not found in the existing settings data, add it as a new item
126 if ( ! $found ) {
127 $settings_data[] = $form_data_item;
128 }
129 }
130 }//end if
131
132 usort( $settings_data, function ( $a, $b ) {
133 return $a['index'] - $b['index'];
134 } );
135
136 return update_option( STOREENGINE_PAYMENTS_SETTINGS_NAME, wp_json_encode( $settings_data ) );
137 }
138
139 /**
140 * @deprecated
141 */
142 public static function disable_payment_method( $type ): bool {
143 $settings = self::get_settings_saved_data();
144 foreach ( $settings as &$setting ) {
145 if ( $setting['type'] === $type ) {
146 $setting['is_enabled'] = false;
147 break;
148 }
149 }
150
151 return update_option( STOREENGINE_PAYMENTS_SETTINGS_NAME, wp_json_encode( $settings ) );
152 }
153 }
154