Start with Sandbox to try everything for free. When you are ready, create a Live app the same way and switch here. Sandbox and Live use different Client IDs and Secrets.
Webhook note: PayPal can only send notifications to a public https:// website. On a local test site the webhook step will fail, which is fine for trying things out.
'settings' === $from ? Admin::url( 'streamgoals-settings' ) : SetupPage::url( $step ); $old = Settings::all(); $post = Admin::post_raw(); $mode = ( $post['paypal_mode'] ?? '' ) === 'live' ? 'live' : 'sandbox'; $cid = Input::text( $post['paypal_client_id'] ?? '', 200 ); $sec = Input::secretUnchanged( (string) ( $post['paypal_client_secret'] ?? '' ) ) ? (string) $old['paypal_client_secret'] : Input::text( $post['paypal_client_secret'], 300 ); if ( '' === $cid || '' === $sec ) { Admin::redirect( $to( 1 ), 'error', 'Please enter both the Client ID and the Secret from your PayPal app.' ); } $changed = $mode !== $old['paypal_mode'] || $cid !== $old['paypal_client_id'] || $sec !== $old['paypal_client_secret']; $update = array( 'paypal_mode' => $mode, 'paypal_client_id' => $cid, 'paypal_client_secret' => $sec ); if ( $changed ) { $update['paypal_webhook_id'] = ''; // a webhook belongs to one specific app/mode delete_option( self::VERIFIED ); } Settings::update( $update ); $client = new Client( new WpTransport(), new WpCache(), $mode, $cid, $sec ); $err = $client->testConnection(); if ( null !== $err ) { Admin::redirect( $to( 1 ), 'error', 'Connection failed. ' . self::scrub( $err, $sec ) . ' Double-check that you copied the right values and that the mode (Sandbox/Live) matches the app.' ); } update_option( self::VERIFIED, self::fingerprint( Settings::all() ), false ); $msg = 'Connected to PayPal (' . ( 'live' === $mode ? 'Live' : 'Sandbox' ) . ').'; $type = 'success'; if ( '' === (string) Settings::get( 'paypal_webhook_id', '' ) ) { try { $id = $client->createWebhook( self::webhookUrl() ); Settings::update( array( 'paypal_webhook_id' => $id ) ); $msg .= ' Payment notifications (webhook) were set up automatically.'; } catch ( PayPalException $e ) { $type = 'warning'; $msg .= ' However, the webhook could not be registered automatically: ' . self::scrub( $e->getMessage(), $sec ) . ' Webhooks need a public https:// site, and a webhook for this address may already exist in your PayPal app (delete it there and try again).'; } } Admin::redirect( $to( 2 ), $type, $msg ); } /** Defensive: make sure an error text can never contain the secret or client id. */ public static function scrub( string $text, string $secret ): string { $text = '' !== $secret ? str_replace( $secret, '[hidden]', $text ) : $text; return Input::text( $text, 400 ); } }