Home / Admin / WP Simple Pay: Block Duplicate Email Addresses
Duplicate Snippet

Embed Snippet on Your Site

WP Simple Pay: Block Duplicate Email Addresses

Block payments if the email address exists at all in the Stripe account.

Code Preview
php
<?php
/**
 * @link https://library.wpcode.com/snippet/ro8xmx35/
 */
add_action(
	'simpay_before_payment_create',
	/**
	 * @param \WP_REST_Request WordPress REST API request.
	 */
	function( $request ) {
		// Retrieve form values.
		$fields = $request->get_param( 'form_values' );
		$email = $fields['simpay_email'];
		// Search for customers based on email.
		$customers = \SimplePay\Core\API\Customers\all(
			array(
				'email' => $email,
			),
			array(
				'api_key' => simpay_get_secret_key(),
			)
		);
		if ( ! empty( $customers->data ) ) {
			throw new Exception( 'Sorry, you already have an account with us.');
		}
		// Payment can be created.
	}
);

Comments

Add a Comment