| @@ 142-183 (lines=42) @@ | ||
| 139 | * @param mixed $renewal_order |
|
| 140 | * @param bool $is_retry Is this a retry process. |
|
| 141 | */ |
|
| 142 | public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) { |
|
| 143 | if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 144 | /* translators: minimum amount */ |
|
| 145 | 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 ) ) ); |
|
| 146 | } |
|
| 147 | ||
| 148 | $order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id(); |
|
| 149 | ||
| 150 | // Get source from order. |
|
| 151 | $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
| 152 | ||
| 153 | if ( ! $prepared_source->customer ) { |
|
| 154 | return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
| 155 | } |
|
| 156 | ||
| 157 | WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
| 158 | ||
| 159 | if ( $is_retry ) { |
|
| 160 | // Passing empty source with charge customer default. |
|
| 161 | $prepared_source->source = ''; |
|
| 162 | } |
|
| 163 | ||
| 164 | $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
| 165 | $request['capture'] = 'true'; |
|
| 166 | $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
| 167 | $response = WC_Stripe_API::request( $request ); |
|
| 168 | ||
| 169 | if ( ! empty( $response->error ) || is_wp_error( $response ) ) { |
|
| 170 | if ( $is_retry ) { |
|
| 171 | /* translators: error message */ |
|
| 172 | $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
| 173 | } |
|
| 174 | ||
| 175 | return $response; // Default catch all errors. |
|
| 176 | } |
|
| 177 | ||
| 178 | $this->process_response( $response, $renewal_order ); |
|
| 179 | ||
| 180 | if ( ! $is_retry ) { |
|
| 181 | return $response; |
|
| 182 | } |
|
| 183 | } |
|
| 184 | ||
| 185 | /** |
|
| 186 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
|
| @@ 210-251 (lines=42) @@ | ||
| 207 | * @param mixed $renewal_order |
|
| 208 | * @param bool $is_retry Is this a retry process. |
|
| 209 | */ |
|
| 210 | public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) { |
|
| 211 | if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 212 | /* translators: minimum amount */ |
|
| 213 | 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 ) ) ); |
|
| 214 | } |
|
| 215 | ||
| 216 | $order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id(); |
|
| 217 | ||
| 218 | // Get source from order |
|
| 219 | $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
| 220 | ||
| 221 | if ( ! $prepared_source->customer ) { |
|
| 222 | return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
| 223 | } |
|
| 224 | ||
| 225 | WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
| 226 | ||
| 227 | if ( $is_retry ) { |
|
| 228 | // Passing empty source with charge customer default. |
|
| 229 | $prepared_source->source = ''; |
|
| 230 | } |
|
| 231 | ||
| 232 | $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
| 233 | $request['capture'] = 'true'; |
|
| 234 | $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
| 235 | $response = WC_Stripe_API::request( $request ); |
|
| 236 | ||
| 237 | if ( ! empty( $response->error ) || is_wp_error( $response ) ) { |
|
| 238 | if ( $is_retry ) { |
|
| 239 | /* translators: error message */ |
|
| 240 | $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
| 241 | } |
|
| 242 | ||
| 243 | return $response; // Default catch all errors. |
|
| 244 | } |
|
| 245 | ||
| 246 | $this->process_response( $response, $renewal_order ); |
|
| 247 | ||
| 248 | if ( ! $is_retry ) { |
|
| 249 | return $response; |
|
| 250 | } |
|
| 251 | } |
|
| 252 | ||
| 253 | /** |
|
| 254 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
|