Code Duplication    Length = 32-33 lines in 2 locations

includes/compat/class-wc-stripe-compat.php 1 location

@@ 226-258 (lines=33) @@
223
	 * @param mixed $renewal_order
224
	 * @param  bool initial_payment
225
	 */
226
	public function process_subscription_payment( $amount = 0.0, $renewal_order ) {
227
		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
228
			/* translators: minimum amount */
229
			return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
230
		}
231
232
		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
233
234
		// Get source from order
235
		$prepared_source = $this->prepare_order_source( $renewal_order );
236
237
		// Or fail :(
238
		if ( ! $prepared_source->customer ) {
239
			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
240
		}
241
242
		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
243
244
		// Make the request
245
		$request            = $this->generate_payment_request( $renewal_order, $prepared_source );
246
		$request['capture'] = 'true';
247
		$request['amount']  = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
248
		$response           = WC_Stripe_API::request( $request );
249
250
		// Process valid response
251
		if ( ! empty( $response->error ) ) {
252
			return $response; // Default catch all errors.
253
		}
254
255
		$this->process_response( $response, $renewal_order );
256
257
		return $response;
258
	}
259
260
	/**
261
	 * Process a retry for subscriptions with default source.

includes/compat/class-wc-stripe-sepa-compat.php 1 location

@@ 139-170 (lines=32) @@
136
	 * @param mixed $renewal_order
137
	 * @param  bool initial_payment
138
	 */
139
	public function process_subscription_payment( $amount = 0.0, $renewal_order ) {
140
		if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) {
141
			/* translators: minimum amount */
142
			return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) );
143
		}
144
145
		$order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id();
146
147
		// Get source from order
148
		$prepared_source = $this->prepare_order_source( $renewal_order );
149
150
		if ( ! $prepared_source->customer ) {
151
			return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) );
152
		}
153
154
		WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" );
155
156
		// Make the request
157
		$request             = $this->generate_payment_request( $renewal_order, $prepared_source );
158
		$request['capture']  = 'true';
159
		$request['amount']   = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] );
160
		$response            = WC_Stripe_API::request( $request );
161
162
		// Process valid response
163
		if ( ! empty( $response->error ) ) {
164
			return $response; // Default catch all errors.
165
		}
166
167
		$this->process_response( $response, $renewal_order );
168
169
		return $response;
170
	}
171
172
	/**
173
	 * Process a retry for subscriptions with default source.