<p class="description">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 <em>different</em> Client IDs and Secrets.</p>
<p class="description"><?php echo '' !== $s['paypal_client_secret'] ? 'A Secret is saved. Leave this empty to keep it, or paste a new one to replace it.' : 'The Secret stays on your server and is never shown again.'; ?></p>
<li>To take <em>real</em> payments PayPal requires a <strong>PayPal Business</strong> account (free; your own name is fine). Practising in Sandbox needs no business account. <a href="https://www.paypal.com/business" target="_blank" rel="noopener noreferrer">Create one</a> or upgrade your existing account in PayPal settings.</li>
<li>Open <a href="https://developer.paypal.com/dashboard/applications" target="_blank" rel="noopener noreferrer">developer.paypal.com/dashboard/applications</a> and log in with that Business account.</li>
<li>At the top, pick <strong>Sandbox</strong> (to practise) or <strong>Live</strong> (real money) and click <strong>Create App</strong>.</li>
<li>Give it any name (for example "My stream"), keep the type <strong>Merchant</strong>, and click <strong>Create App</strong>.</li>
<li>On the next page, copy the <strong>Client ID</strong>. Under <strong>Secret key 1</strong> click <strong>Show</strong> and copy the <strong>Secret</strong>.</li>
<li>Choose the same mode below (Sandbox or Live), paste both values, and press the button. We will check them and set up payment notifications (the webhook) for you.</li>
</ol>
<p class="description">Webhook note: PayPal can only send notifications to a public <strong>https://</strong> website. On a local test site the webhook step will fail, which is fine for trying things out.</p>
<?php
}
/** admin-post: save credentials, test, register webhook. */
public static function handle(): void {
Admin::guard( 'sg_paypal_connect' );
$from = Admin::post_str( 'return', 20 );
// Computed lazily: the wizard lives at a different menu slug depending on whether PayPal is connected.
$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.' );