<?

	// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
	require __DIR__  . '/autoload.php';

	// 2. Provide your Secret Key. Replace the given one with your app clientId, and Secret
	// https://developer.paypal.com/webapps/developer/applications/myapps
	$apiContext = new \PayPal\Rest\ApiContext(
		new \PayPal\Auth\OAuthTokenCredential(
			'AcaMHeauY5hyppiCN-lQBIfO3xEN-Xp55b_aKMcy9MaD0GeOdCjlsyUvdU6O-9-VLhyr8oavVCuixlpc',     // ClientID
			'EC6zSGG_ZbuiuEV-1B2csp8U46qAA6wzeNhr5cmx4IPVTQuZZQZz3zHZHGI-y8IGDKr-5njNJl_q_iZQ'      // ClientSecret
		)
	);

	// 3. Lets try to create a Payment
	// https://developer.paypal.com/docs/api/payments/#payment_create
	$payer = new \PayPal\Api\Payer();
	$payer->setPaymentMethod('paypal');

	$amount = new \PayPal\Api\Amount();
	$amount->setTotal('1.00');
	$amount->setCurrency('SGD');

	$transaction = new \PayPal\Api\Transaction();
	$transaction->setAmount($amount);

	$redirectUrls = new \PayPal\Api\RedirectUrls();
	$redirectUrls->setReturnUrl("https://www.event-sp.com/IIW2020/register/acknowledge.php")
		->setCancelUrl("https://www.event-sp.com/IIW2020/register/");

	$payment = new \PayPal\Api\Payment();
	$payment->setIntent('sale')
		->setPayer($payer)
		->setTransactions(array($transaction))
		->setRedirectUrls($redirectUrls);

	// 4. Make a Create Call and print the values
	try {
		$payment->create($apiContext);
		echo $payment;

		echo "\n\nRedirect user to approval_url: " . $payment->getApprovalLink() . "\n";
	}
	catch (\PayPal\Exception\PayPalConnectionException $ex) {
		// This will print the detailed information on the exception.
		//REALLY HELPFUL FOR DEBUGGING
		echo $ex->getData();
	}

?>