Code Duplication    Length = 24-34 lines in 6 locations

includes/gateways/stripe/includes/class-give-stripe-invoice.php 1 location

@@ 34-60 (lines=27) @@
31
		 *
32
		 * @return \Stripe\Invoice
33
		 */
34
		public function retrieve( $id ) {
35
			try {
36
37
				// Set Application Information.
38
				give_stripe_set_app_info();
39
40
				// Retrieve Invoice by ID.
41
				$invoice = \Stripe\Invoice::retrieve( $id );
42
			} catch( Exception $e ) {
43
44
				// Something went wrong outside of Stripe.
45
				give_record_gateway_error(
46
					__( 'Stripe - Invoices Error', 'give' ),
47
					sprintf(
48
						/* translators: %s Exception Message. */
49
						__( 'An error while retrieving invoice. Details: %s', 'give' ),
50
						$e->getMessage()
51
					)
52
				);
53
				give_set_error( 'Stripe Error', __( 'An error occurred while retrieving invoice. Please try again.', 'give' ) );
54
				give_send_back_to_checkout( '?payment-mode=' . give_clean( $_GET['payment-mode'] ) );
55
56
				 return false;
57
			}
58
59
			return $invoice;
60
		}
61
	}
62
}
63

includes/gateways/stripe/includes/class-give-stripe-payment-intent.php 2 locations

@@ 41-69 (lines=29) @@
38
		 *
39
		 * @return \Stripe\PaymentIntent
40
		 */
41
		public function create( $args ) {
42
43
			// Add application fee, if the Stripe premium add-on is not active.
44
			if ( ! defined( 'GIVE_STRIPE_VERSION' ) ) {
45
				$args['application_fee_amount'] = give_stripe_get_application_fee_amount( $args['amount'] );
46
			}
47
48
			// Set Stripe Application Info.
49
			give_stripe_set_app_info();
50
51
			try {
52
				return \Stripe\PaymentIntent::create(
53
					$args,
54
					give_stripe_get_connected_account_options()
55
				);
56
			} catch ( Exception $e ) {
57
58
				give_record_gateway_error(
59
					__( 'Stripe Payment Intent Error', 'give' ),
60
					sprintf(
61
						/* translators: %s Exception Error Message */
62
						__( 'Unable to create a payment intent. Details: %s', 'give' ),
63
						$e->getMessage()
64
					)
65
				);
66
67
				give_set_error( 'stripe_payment_intent_error', __( 'Error creating payment intent with Stripe. Please try again.', 'give' ) );
68
			} // End try().
69
		}
70
71
		/**
72
		 * This function is used to retrieve payment intent in Stripe.
@@ 117-146 (lines=30) @@
114
		 *
115
		 * @return \Stripe\PaymentIntent
116
		 */
117
		public function update( $client_secret, $args ) {
118
119
			// Add application fee, if the Stripe premium add-on is not active.
120
			if ( ! defined( GIVE_STRIPE_VERSION ) ) {
121
				$args['application_fee_amount'] = give_stripe_get_application_fee_amount( $args['amount'] );
122
			}
123
124
			// Set Stripe Application Info.
125
			give_stripe_set_app_info();
126
127
			try {
128
				return \Stripe\PaymentIntent::update(
129
					$client_secret,
130
					$args,
131
					give_stripe_get_connected_account_options()
132
				);
133
			} catch ( Exception $e ) {
134
135
				give_record_gateway_error(
136
					__( 'Stripe Payment Intent Error', 'give' ),
137
					sprintf(
138
						/* translators: %s Exception Error Message */
139
						__( 'Unable to update a payment intent. Details: %s', 'give' ),
140
						$e->getMessage()
141
					)
142
				);
143
144
				give_set_error( 'stripe_payment_intent_error', __( 'Error updating payment intent with Stripe. Please try again.', 'give' ) );
145
			} // End try().
146
		}
147
	}
148
}
149

includes/gateways/stripe/includes/class-give-stripe-payment-method.php 2 locations

@@ 36-59 (lines=24) @@
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.
@@ 68-91 (lines=24) @@
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
		 * Fetch all payment methods of the customer.

includes/gateways/stripe/includes/give-stripe-helpers.php 1 location

@@ 764-797 (lines=34) @@
761
 *
762
 * @return void
763
 */
764
function give_stripe_set_api_key() {
765
766
    try {
767
768
		// Fetch secret key.
769
        $secret_key = give_stripe_get_secret_key();
770
771
        // Set secret key.
772
		\Stripe\Stripe::setApiKey( $secret_key );
773
774
	} catch ( \Stripe\Error\Base $e ) {
775
776
		// Log Error.
777
		$this->log_error( $e );
778
779
	} catch ( Exception $e ) {
780
781
		// Something went wrong outside of Stripe.
782
		give_record_gateway_error(
783
			__( 'Stripe Error', 'give' ),
784
			sprintf(
785
			/* translators: %s Exception Message Body */
786
				__( 'Unable to set Stripe API Key. Details: %s', 'give' ),
787
				$e->getMessage()
788
			)
789
		);
790
		give_set_error( 'stripe_error', __( 'An error occurred while processing the donation. Please try again.', 'give' ) );
791
792
		// Send donor back to donation form page.
793
		give_send_back_to_checkout( '?payment-mode=' . give_clean( $_GET['payment-mode'] ) );
794
795
	}
796
797
}
798
799
/**
800
 * This function is used to fetch the webhook key used to store in options table.