PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0
GiveWP – Donation Plugin and Fundraising Platform v4.18.0
4.18.0 4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 All 257 releases
give / includes / gateways / stripe / includes / class-give-stripe-payment-method.php

class-give-stripe-payment-method.php in GiveWP – Donation Plugin and Fundraising Platform 4.18.0, at includes/gateways/stripe/includes/class-give-stripe-payment-method.php

170 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Give - Stripe Core | Payment Method API
4 *
5 * @since 2.5.0
6 *
7 * @package Give
8 * @subpackage Stripe Core
9 * @copyright Copyright (c) 2019, GiveWP
10 * @license https://opensource.org/licenses/gpl-license GNU Public License
11 */
12
13 // Exit, if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 /**
19 * Check for class Give_Stripe_Payment_Method exists.
20 *
21 * @since 2.5.0
22 */
23 if ( ! class_exists( 'Give_Stripe_Payment_Method' ) ) {
24
25 class Give_Stripe_Payment_Method {
26
27 /**
28 * Create Payment Method.
29 *
30 * @param array $args Payment Method Arguments.
31 *
32 * @since 2.5.0
33 *
34 * @return \Stripe\PaymentMethod
35 */
36 public function create( $args ) {
37
38 try {
39
40 give_stripe_set_app_info();
41
42 $payment_method = \Stripe\PaymentMethod::create( $args, give_stripe_get_connected_account_options() );
43
44 } catch ( Exception $e ) {
45 give_record_gateway_error(
46 __( 'Stripe Payment Method Error', 'give' ),
47 sprintf(
48 /* translators: %s Exception Message Body */
49 __( 'The Stripe Gateway returned an error while creating the payment method. Details: %s', 'give' ),
50 $e
51 )
52 );
53 give_set_error( 'stripe_error', __( 'An occurred while creating the payment method. Please try again.', 'give' ) );
54 give_send_back_to_checkout( '?payment-mode=' . give_clean( $_GET['payment-mode'] ) );
55 return false;
56 }
57
58 return $payment_method;
59 }
60
61 /**
62 * Retrieves the payment method.
63 *
64 * @param string $id Payment Intent ID.
65 *
66 * @return \Stripe\PaymentMethod
67 */
68 public function retrieve( $id ) {
69
70 try {
71
72 give_stripe_set_app_info();
73
74 $payment_method_details = \Stripe\PaymentMethod::retrieve( $id, give_stripe_get_connected_account_options() );
75
76 } catch ( Exception $e ) {
77 give_record_gateway_error(
78 __( 'Stripe Payment Method Error', 'give' ),
79 sprintf(
80 /* translators: %s Exception Message Body */
81 __( 'The Stripe Gateway returned an error while retrieving the payment method of the customer. Details: %s', 'give' ),
82 $e->getMessage()
83 )
84 );
85 give_set_error( 'stripe_error', __( 'An occurred while retrieving the payment method of the customer. Please try again.', 'give' ) );
86 give_send_back_to_checkout( '?payment-mode=' . give_clean( $_GET['payment-mode'] ) );
87 return false;
88 }
89
90 return $payment_method_details;
91 }
92
93 /**
94 * This function is used to update existing payment method.
95 *
96 * @param string $id Payment Method ID of Stripe.
97 * @param array $args List of arguments to update.
98 *
99 * @since 2.5.10
100 *
101 * @return bool|\Stripe\PaymentMethod
102 */
103 public function update( $id, $args ) {
104
105 give_stripe_set_app_info();
106
107 $payment_method = false;
108
109 try {
110 $payment_method = \Stripe\PaymentMethod::update( $id, $args, give_stripe_get_connected_account_options() );
111 } catch ( Exception $e ) {
112 give_record_gateway_error(
113 __( 'Stripe Payment Method Error', 'give' ),
114 sprintf(
115 /* translators: %s Exception Message Body */
116 __( 'The Stripe Gateway returned an error while updating the payment method of the customer. Details: %s', 'give' ),
117 $e->getMessage()
118 )
119 );
120 give_set_error( 'stripe_error', __( 'An occurred while retrieving the payment method of the customer. Please try again.', 'give' ) );
121 give_send_back_to_checkout( '?payment-mode=' . give_clean( $_GET['payment-mode'] ) );
122 }
123
124 return $payment_method;
125 }
126
127 /**
128 * Fetch all payment methods of the customer.
129 *
130 * @param string $customer_id Stripe Customer ID.
131 * @param string $type Stripe Payment Type.
132 *
133 * @since 2.5.0
134 *
135 * @return \Stripe\PaymentMethod
136 */
137 public function list_all( $customer_id, $type = 'card' ) {
138
139 try {
140
141 give_stripe_set_app_info();
142
143 $all_payment_methods = \Stripe\PaymentMethod::all(
144 array(
145 'customer' => $customer_id,
146 'type' => $type,
147 'limit' => 100,
148 ),
149 give_stripe_get_connected_account_options()
150 );
151
152 } catch ( Exception $e ) {
153 give_record_gateway_error(
154 __( 'Stripe Payment Method Error', 'give' ),
155 sprintf(
156 /* translators: %s Exception Message Body */
157 __( 'The Stripe Gateway returned an error while fetching the list of payment methods of the customer. Details: %s', 'give' ),
158 $e->getMessage()
159 )
160 );
161 give_set_error( 'stripe_error', __( 'An occurred while fetching the list of payment methods of the customer. Please try again.', 'give' ) );
162 give_send_back_to_checkout( '?payment-mode=' . give_clean( $_GET['payment-mode'] ) );
163 return false;
164 }
165
166 return $all_payment_methods;
167 }
168 }
169 }
170