Last active
September 5, 2022 03:52
-
-
Save jaypatel512/94e626b684f6fefa5078 to your computer and use it in GitHub Desktop.
Adding File based SDK Configurations: https://github.com/paypal/PayPal-PHP-SDK/wiki/File-based-Configurations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader | |
require __DIR__ . '/PayPal-PHP-SDK/autoload.php'; | |
// 2. Define PP_CONFIG_PATH directory | |
if(!defined("PP_CONFIG_PATH")) { | |
define("PP_CONFIG_PATH", __DIR__); | |
} | |
// 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->setIntent('sale') | |
->setPayer($payer) | |
->setTransactions(array($transaction)) | |
->setRedirectUrls($redirectUrls); | |
// 4. Make a Create Call and print the values | |
try { | |
$payment->create(); | |
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(); | |
} |
You are right @kdrezo. Will update that.
I believe you have missed $payment = new \PayPal\Api\Payment();
before $payment->setIntent('sale')
(line 25).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello sorry for my poor english
but I think
$creditCard->create($apiContext);
must be,
$creditCard->create();