| @@ 397-419 (lines=23) @@ | ||
| 394 | * @param array $payment_meta associative array of meta data required for automatic payments |
|
| 395 | * @return array |
|
| 396 | */ |
|
| 397 | public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
| 398 | if ( $this->id === $payment_method_id ) { |
|
| 399 | ||
| 400 | if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
| 401 | ||
| 402 | // Allow empty stripe customer id during subscription renewal. It will be added when processing payment if required. |
|
| 403 | if ( ! isset( $_POST['wc_order_action'] ) || 'wcs_process_renewal' !== $_POST['wc_order_action'] ) { |
|
| 404 | throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
| 405 | } |
|
| 406 | } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
| 407 | throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
| 408 | } |
|
| 409 | ||
| 410 | if ( |
|
| 411 | ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 412 | && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
| 413 | && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 414 | && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
| 415 | ||
| 416 | throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
| 417 | } |
|
| 418 | } |
|
| 419 | } |
|
| 420 | ||
| 421 | /** |
|
| 422 | * Render the payment method used for a subscription in the "My Subscriptions" table |
|
| @@ 505-528 (lines=24) @@ | ||
| 502 | * @param array $payment_meta associative array of meta data required for automatic payments |
|
| 503 | * @return array |
|
| 504 | */ |
|
| 505 | public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
| 506 | if ( $this->id === $payment_method_id ) { |
|
| 507 | ||
| 508 | if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
| 509 | ||
| 510 | // Allow empty stripe customer id during subscription renewal. It will be added when processing payment if required. |
|
| 511 | if ( ! isset( $_POST['wc_order_action'] ) || 'wcs_process_renewal' !== $_POST['wc_order_action'] ) { |
|
| 512 | throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
| 513 | } |
|
| 514 | } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
| 515 | throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
| 516 | } |
|
| 517 | ||
| 518 | if ( |
|
| 519 | ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) && ( |
|
| 520 | 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) |
|
| 521 | && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) |
|
| 522 | && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'pm_' ) |
|
| 523 | ) |
|
| 524 | ) { |
|
| 525 | throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_", "pm_", or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
| 526 | } |
|
| 527 | } |
|
| 528 | } |
|
| 529 | ||
| 530 | /** |
|
| 531 | * Render the payment method used for a subscription in the "My Subscriptions" table |
|