|
|
|
@ -83,27 +83,57 @@ function edds_stripe_connect_url() {
|
|
|
|
|
*/
|
|
|
|
|
function edds_process_gateway_connect_completion() {
|
|
|
|
|
|
|
|
|
|
if( ! isset( $_GET['edd_gateway_connect_completion'] ) || 'stripe_connect' !== $_GET['edd_gateway_connect_completion'] || ! isset( $_GET['state'] ) ) {
|
|
|
|
|
$redirect_screen = ! empty( $_GET['redirect_screen'] ) ? sanitize_text_field( $_GET['redirect_screen'] ) : '';
|
|
|
|
|
|
|
|
|
|
// A cancelled connection doesn't contain the completion or state values, but we do need to listen for the redirect_screen for the wizard.
|
|
|
|
|
if (
|
|
|
|
|
isset( $_GET['edd_gateway_connect_error'] ) &&
|
|
|
|
|
filter_var( $_GET['edd_gateway_connect_error'], FILTER_VALIDATE_BOOLEAN ) &&
|
|
|
|
|
! empty( $redirect_screen )
|
|
|
|
|
) {
|
|
|
|
|
$error_redirect = '';
|
|
|
|
|
|
|
|
|
|
switch ( $redirect_screen ) {
|
|
|
|
|
case 'onboarding-wizard':
|
|
|
|
|
$error_redirect = admin_url( 'edit.php?post_type=download&page=edd-onboarding-wizard¤t_step=payment_methods' );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( ! empty( $error_redirect ) ) {
|
|
|
|
|
wp_safe_redirect( esc_url_raw( $error_redirect ) );
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( ! isset( $_GET['edd_gateway_connect_completion'] ) || 'stripe_connect' !== $_GET['edd_gateway_connect_completion'] || ! isset( $_GET['state'] ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( ! current_user_can( 'manage_shop_settings' ) ) {
|
|
|
|
|
if ( ! current_user_can( 'manage_shop_settings' ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( headers_sent() ) {
|
|
|
|
|
if ( headers_sent() ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$edd_credentials_url = add_query_arg( array(
|
|
|
|
|
'live_mode' => (int) ! edd_is_test_mode(),
|
|
|
|
|
'state' => sanitize_text_field( $_GET['state'] ),
|
|
|
|
|
'customer_site_url' => admin_url( 'edit.php?post_type=download' ),
|
|
|
|
|
), 'https://easydigitaldownloads.com/?edd_gateway_connect_credentials=stripe_connect' );
|
|
|
|
|
$customer_site_url = admin_url( 'edit.php?post_type=download' );
|
|
|
|
|
if ( ! empty( $redirect_screen ) ) {
|
|
|
|
|
$customer_site_url = add_query_arg( 'redirect_screen', $redirect_screen, $customer_site_url );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$edd_credentials_url = add_query_arg(
|
|
|
|
|
array(
|
|
|
|
|
'live_mode' => (int) ! edd_is_test_mode(),
|
|
|
|
|
'state' => sanitize_text_field( $_GET['state'] ),
|
|
|
|
|
'customer_site_url' => urlencode( $customer_site_url ),
|
|
|
|
|
),
|
|
|
|
|
'https://easydigitaldownloads.com/?edd_gateway_connect_credentials=stripe_connect'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$response = wp_remote_get( esc_url_raw( $edd_credentials_url ) );
|
|
|
|
|
|
|
|
|
|
if( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
|
|
|
|
|
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
|
|
|
|
|
$message = '<p>' . sprintf(
|
|
|
|
|
/* translators: %1$s Opening anchor tag, do not translate. %2$s Closing anchor tag, do not translate. */
|
|
|
|
|
__( 'There was an error getting your Stripe credentials. Please %1$stry again%2$s. If you continue to have this problem, please contact support.', 'easy-digital-downloads' ),
|
|
|
|
@ -116,7 +146,7 @@ function edds_process_gateway_connect_completion() {
|
|
|
|
|
$data = json_decode( $response['body'], true );
|
|
|
|
|
$data = $data['data'];
|
|
|
|
|
|
|
|
|
|
if( edd_is_test_mode() ) {
|
|
|
|
|
if ( edd_is_test_mode() ) {
|
|
|
|
|
edd_update_option( 'test_publishable_key', sanitize_text_field( $data['publishable_key'] ) );
|
|
|
|
|
edd_update_option( 'test_secret_key', sanitize_text_field( $data['secret_key'] ) );
|
|
|
|
|
} else {
|
|
|
|
@ -125,7 +155,18 @@ function edds_process_gateway_connect_completion() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
edd_update_option( 'stripe_connect_account_id', sanitize_text_field( $data['stripe_user_id'] ) );
|
|
|
|
|
wp_redirect( esc_url_raw( admin_url( 'edit.php?post_type=download&page=edd-settings&tab=gateways§ion=edd-stripe' ) ) );
|
|
|
|
|
|
|
|
|
|
$redirect_url = admin_url( 'edit.php?post_type=download&page=edd-settings&tab=gateways§ion=edd-stripe' );
|
|
|
|
|
|
|
|
|
|
if ( ! empty( $redirect_screen ) ) {
|
|
|
|
|
switch ( $redirect_screen ) {
|
|
|
|
|
case 'onboarding-wizard':
|
|
|
|
|
$redirect_url = admin_url( 'edit.php?post_type=download&page=edd-onboarding-wizard¤t_step=payment_methods' );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wp_safe_redirect( esc_url_raw( $redirect_url ) );
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -178,7 +219,7 @@ function edds_stripe_connect_disconnect_url() {
|
|
|
|
|
function edds_stripe_connect_process_disconnect() {
|
|
|
|
|
// Do not need to handle this request, bail.
|
|
|
|
|
if (
|
|
|
|
|
! ( isset( $_GET['page'] ) && 'edd-settings' === $_GET['page'] ) ||
|
|
|
|
|
! ( isset( $_GET['page'] ) && ( 'edd-settings' === $_GET['page'] || 'edd-onboarding-wizard' === $_GET['page'] ) ) ||
|
|
|
|
|
! isset( $_GET['edds-stripe-disconnect'] )
|
|
|
|
|
) {
|
|
|
|
|
return;
|
|
|
|
@ -337,7 +378,7 @@ function edds_stripe_connect_setting_field() {
|
|
|
|
|
class="edds-stripe-connect-acount-info notice inline"
|
|
|
|
|
data-account-id="<?php echo esc_attr( $stripe_connect_account_id ); ?>"
|
|
|
|
|
data-nonce="<?php echo wp_create_nonce( 'edds-stripe-connect-account-information' ); ?>"
|
|
|
|
|
>
|
|
|
|
|
<?php echo ( ! empty( $_GET['page'] ) && 'edd-onboarding-wizard' === $_GET['page'] ) ? ' data-onboarding-wizard="true"' : ''; ?>>
|
|
|
|
|
<p><span class="spinner is-active"></span>
|
|
|
|
|
<em><?php esc_html_e( 'Retrieving account information...', 'easy-digital-downloads' ); ?></em>
|
|
|
|
|
</div>
|
|
|
|
|