diff --git a/sample/payments/AuthorizationCapture.php b/sample/payments/AuthorizationCapture.php index d87474a..ab414f2 100644 --- a/sample/payments/AuthorizationCapture.php +++ b/sample/payments/AuthorizationCapture.php @@ -15,7 +15,7 @@ use PayPal\Api\FundingInstrument; use PayPal\Api\Transaction; // create payment to get authorization Id -$authId = createAuthorization(); +$authId = createAuthorization($apiContext); $amt = new Amount(); $amt->setCurrency("USD"); @@ -54,7 +54,7 @@ try { setLine1("3909 Witmer Road"); @@ -95,7 +95,7 @@ function createAuthorization() $payment->setPayer($payer); $payment->setTransactions(array($transaction)); - $paymnt = $payment->create(); + $paymnt = $payment->create($apiContext); $resArray = $paymnt->toArray(); return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; diff --git a/sample/payments/GetAuthorization.php b/sample/payments/GetAuthorization.php index c72e0e4..d27e1ed 100644 --- a/sample/payments/GetAuthorization.php +++ b/sample/payments/GetAuthorization.php @@ -15,7 +15,7 @@ use PayPal\Api\FundingInstrument; use PayPal\Api\Transaction; // create payment to get authorization Id -$authId = createAuthorization(); +$authId = createAuthorization($apiContext); // ### GetAuthorization // GetAuthorization by posting to the APIService @@ -40,7 +40,7 @@ try { setLine1("3909 Witmer Road"); @@ -81,7 +81,7 @@ function createAuthorization() $payment->setPayer($payer); $payment->setTransactions(array($transaction)); - $paymnt = $payment->create(); + $paymnt = $payment->create($apiContext); $resArray = $paymnt->toArray(); return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; diff --git a/sample/payments/GetCapture.php b/sample/payments/GetCapture.php index 9b08564..474fc5e 100644 --- a/sample/payments/GetCapture.php +++ b/sample/payments/GetCapture.php @@ -12,9 +12,10 @@ use PayPal\Api\Payer; use PayPal\Api\Payment; use PayPal\Api\FundingInstrument; use PayPal\Api\Transaction; +use PayPal\Api\Authorization; // create payment to get authorization Id -$authId = createAuthorization(); +$authId = createAuthorization($apiContext); $amt = new Amount(); $amt->setCurrency("USD"); $amt->setTotal("1.00"); @@ -62,7 +63,7 @@ try { setLine1("3909 Witmer Road"); @@ -103,7 +104,7 @@ function createAuthorization() $payment->setPayer($payer); $payment->setTransactions(array($transaction)); - $paymnt = $payment->create(); + $paymnt = $payment->create($apiContext); $resArray = $paymnt->toArray(); return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; diff --git a/sample/payments/RefundCapture.php b/sample/payments/RefundCapture.php index 8c3583a..65135ec 100644 --- a/sample/payments/RefundCapture.php +++ b/sample/payments/RefundCapture.php @@ -5,6 +5,7 @@ // using the Capture API. // API used: /v1/payments/capture/{}/refund require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\Authorization; use PayPal\Api\Capture; use PayPal\Api\Refund; use PayPal\Api\Address; @@ -14,9 +15,11 @@ use PayPal\Api\Payer; use PayPal\Api\Payment; use PayPal\Api\FundingInstrument; use PayPal\Api\Transaction; +use PayPal\Rest\ApiContext; +use PayPal\Auth\OAuthTokenCredential; // create payment to get authorization Id -$authId = createAuthorization(); +$authId = createAuthorization($apiContext); $amt = new Amount(); $amt->setCurrency("USD"); @@ -24,7 +27,6 @@ $amt->setTotal("1.00"); ### Capture $captur = new Capture(); -$captur->setId($authId); $captur->setAmount($amt); // get the authorization @@ -48,14 +50,17 @@ try { $refund = new Refund(); -$refund->setId($capt->getId()); $refund->setAmount($amt); - $capture = Capture::get($capt->getId(), $apiContext); + +// create new API context +$context = new ApiContext(new OAuthTokenCredential( + 'Aer9WxCa2q0dlmoyWv2n__xE10ttwuXL3pNLzLFU30atoUda5bKGh_lUqSzy', + 'EIUvhhC4ga-Fy5N7vIZPRBOpcdoi2iVRhTwJ_ZhMD9RdZZSMtSGSNLAwq-ND')); try { // (See bootstrap.php for more on `ApiContext`) - $captureRefund = $capture->refund($refund, $apiContext); + $captureRefund = $capture->refund($refund, $context); } catch (\PPConnectionException $ex) { echo "Exception: " . $ex->getMessage() . PHP_EOL; var_dump($ex->getData()); @@ -71,7 +76,7 @@ try { setLine1("3909 Witmer Road"); @@ -101,7 +106,7 @@ function createAuthorization() $amount = new Amount(); $amount->setCurrency("USD"); - $amount->setTotal("1.00"); + $amount->setTotal("10.00"); $transaction = new Transaction(); $transaction->setAmount($amount); @@ -112,7 +117,7 @@ function createAuthorization() $payment->setPayer($payer); $payment->setTransactions(array($transaction)); - $paymnt = $payment->create(); + $paymnt = $payment->create($apiContext); $resArray = $paymnt->toArray(); return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; diff --git a/sample/payments/VoidAuthorization.php b/sample/payments/VoidAuthorization.php index 147ff07..dff13be 100644 --- a/sample/payments/VoidAuthorization.php +++ b/sample/payments/VoidAuthorization.php @@ -15,7 +15,7 @@ use PayPal\Api\FundingInstrument; use PayPal\Api\Transaction; // create payment to get authorization Id -$authId = createAuthorization(); +$authId = createAuthorization($apiContext); $authorization = Authorization::get($authId, $apiContext); @@ -42,7 +42,7 @@ try { setLine1("3909 Witmer Road"); @@ -83,7 +83,7 @@ function createAuthorization() $payment->setPayer($payer); $payment->setTransactions(array($transaction)); - $paymnt = $payment->create(); + $paymnt = $payment->create($apiContext); $resArray = $paymnt->toArray(); return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];