-
-
Save jaypatel512/a2b037ab5ddc51fa7280 to your computer and use it in GitHub Desktop.
<?php | |
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader | |
require __DIR__ . '/PayPal-PHP-SDK/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( | |
'AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS', // ClientID | |
'EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL' // ClientSecret | |
) | |
); | |
// Step 2.1 : Between Step 2 and Step 3 | |
$apiContext->setConfig( | |
array( | |
'log.LogEnabled' => true, | |
'log.FileName' => 'PayPal.log', | |
'log.LogLevel' => 'DEBUG' | |
) | |
); | |
// 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('USD'); | |
$transaction = new \PayPal\Api\Transaction(); | |
$transaction->setAmount($amount); | |
$redirectUrls = new \PayPal\Api\RedirectUrls(); | |
$redirectUrls->setReturnUrl("https://example.com/your_redirect_url.html") | |
->setCancelUrl("https://example.com/your_cancel_url.html"); | |
$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(); | |
} |
I found a warning using my mac terminal when I using Terminal,
Warning: date(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /Applications/XAMPP/xamppfiles/htdocs/paypaltesting/public/vendor/paypal/rest-api-sdk-php/lib/PayPal/Log/PayPalLogger.php on line 80
Can some one help me?
I have the same problem that @mingtaosam and im using mac terminal too.
I solved this error by adding timezone at the begging of the file. Check here for yours.
date_default_timezone_set('Asia/Hong_Kong');
oh my god,what does this mean?
[25-08-2016 11:55:15] PayPal\Core\PayPalHttpConnection : INFO: POST https://api.sandbox.paypal.com/v1/oauth2/token
[25-08-2016 11:55:19] PayPal\Core\PayPalHttpConnection : INFO: Invalid or no certificate authority found - Retrying using bundled CA certs file
[25-08-2016 11:55:22] PayPal\Core\PayPalHttpConnection : INFO: Response Status : 200
[25-08-2016 11:55:22] PayPal\Core\PayPalHttpConnection : INFO: POST https://api.sandbox.paypal.com/v1/vault/credit-cards
[25-08-2016 11:55:24] PayPal\Core\PayPalHttpConnection : INFO: Invalid or no certificate authority found - Retrying using bundled CA certs file
[25-08-2016 11:55:25] PayPal\Core\PayPalHttpConnection : INFO: Response Status : 201