forked from LiveCarta/PayPal-PHP-SDK
passing API context to create authorization
This commit is contained in:
@@ -15,7 +15,7 @@ use PayPal\Api\FundingInstrument;
|
|||||||
use PayPal\Api\Transaction;
|
use PayPal\Api\Transaction;
|
||||||
|
|
||||||
// create payment to get authorization Id
|
// create payment to get authorization Id
|
||||||
$authId = createAuthorization();
|
$authId = createAuthorization($apiContext);
|
||||||
|
|
||||||
$amt = new Amount();
|
$amt = new Amount();
|
||||||
$amt->setCurrency("USD");
|
$amt->setCurrency("USD");
|
||||||
@@ -54,7 +54,7 @@ try {
|
|||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
<?php
|
<?php
|
||||||
function createAuthorization()
|
function createAuthorization($apiContext)
|
||||||
{
|
{
|
||||||
$addr = new Address();
|
$addr = new Address();
|
||||||
$addr->setLine1("3909 Witmer Road");
|
$addr->setLine1("3909 Witmer Road");
|
||||||
@@ -95,7 +95,7 @@ function createAuthorization()
|
|||||||
$payment->setPayer($payer);
|
$payment->setPayer($payer);
|
||||||
$payment->setTransactions(array($transaction));
|
$payment->setTransactions(array($transaction));
|
||||||
|
|
||||||
$paymnt = $payment->create();
|
$paymnt = $payment->create($apiContext);
|
||||||
$resArray = $paymnt->toArray();
|
$resArray = $paymnt->toArray();
|
||||||
|
|
||||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use PayPal\Api\FundingInstrument;
|
|||||||
use PayPal\Api\Transaction;
|
use PayPal\Api\Transaction;
|
||||||
|
|
||||||
// create payment to get authorization Id
|
// create payment to get authorization Id
|
||||||
$authId = createAuthorization();
|
$authId = createAuthorization($apiContext);
|
||||||
|
|
||||||
// ### GetAuthorization
|
// ### GetAuthorization
|
||||||
// GetAuthorization by posting to the APIService
|
// GetAuthorization by posting to the APIService
|
||||||
@@ -40,7 +40,7 @@ try {
|
|||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
<?php
|
<?php
|
||||||
function createAuthorization()
|
function createAuthorization($apiContext)
|
||||||
{
|
{
|
||||||
$addr = new Address();
|
$addr = new Address();
|
||||||
$addr->setLine1("3909 Witmer Road");
|
$addr->setLine1("3909 Witmer Road");
|
||||||
@@ -81,7 +81,7 @@ function createAuthorization()
|
|||||||
$payment->setPayer($payer);
|
$payment->setPayer($payer);
|
||||||
$payment->setTransactions(array($transaction));
|
$payment->setTransactions(array($transaction));
|
||||||
|
|
||||||
$paymnt = $payment->create();
|
$paymnt = $payment->create($apiContext);
|
||||||
$resArray = $paymnt->toArray();
|
$resArray = $paymnt->toArray();
|
||||||
|
|
||||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||||
|
|||||||
@@ -12,9 +12,10 @@ use PayPal\Api\Payer;
|
|||||||
use PayPal\Api\Payment;
|
use PayPal\Api\Payment;
|
||||||
use PayPal\Api\FundingInstrument;
|
use PayPal\Api\FundingInstrument;
|
||||||
use PayPal\Api\Transaction;
|
use PayPal\Api\Transaction;
|
||||||
|
use PayPal\Api\Authorization;
|
||||||
|
|
||||||
// create payment to get authorization Id
|
// create payment to get authorization Id
|
||||||
$authId = createAuthorization();
|
$authId = createAuthorization($apiContext);
|
||||||
$amt = new Amount();
|
$amt = new Amount();
|
||||||
$amt->setCurrency("USD");
|
$amt->setCurrency("USD");
|
||||||
$amt->setTotal("1.00");
|
$amt->setTotal("1.00");
|
||||||
@@ -62,7 +63,7 @@ try {
|
|||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
<?php
|
<?php
|
||||||
function createAuthorization()
|
function createAuthorization($apiContext)
|
||||||
{
|
{
|
||||||
$addr = new Address();
|
$addr = new Address();
|
||||||
$addr->setLine1("3909 Witmer Road");
|
$addr->setLine1("3909 Witmer Road");
|
||||||
@@ -103,7 +104,7 @@ function createAuthorization()
|
|||||||
$payment->setPayer($payer);
|
$payment->setPayer($payer);
|
||||||
$payment->setTransactions(array($transaction));
|
$payment->setTransactions(array($transaction));
|
||||||
|
|
||||||
$paymnt = $payment->create();
|
$paymnt = $payment->create($apiContext);
|
||||||
$resArray = $paymnt->toArray();
|
$resArray = $paymnt->toArray();
|
||||||
|
|
||||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
// using the Capture API.
|
// using the Capture API.
|
||||||
// API used: /v1/payments/capture/{<captureID>}/refund
|
// API used: /v1/payments/capture/{<captureID>}/refund
|
||||||
require __DIR__ . '/../bootstrap.php';
|
require __DIR__ . '/../bootstrap.php';
|
||||||
|
use PayPal\Api\Authorization;
|
||||||
use PayPal\Api\Capture;
|
use PayPal\Api\Capture;
|
||||||
use PayPal\Api\Refund;
|
use PayPal\Api\Refund;
|
||||||
use PayPal\Api\Address;
|
use PayPal\Api\Address;
|
||||||
@@ -14,9 +15,11 @@ use PayPal\Api\Payer;
|
|||||||
use PayPal\Api\Payment;
|
use PayPal\Api\Payment;
|
||||||
use PayPal\Api\FundingInstrument;
|
use PayPal\Api\FundingInstrument;
|
||||||
use PayPal\Api\Transaction;
|
use PayPal\Api\Transaction;
|
||||||
|
use PayPal\Rest\ApiContext;
|
||||||
|
use PayPal\Auth\OAuthTokenCredential;
|
||||||
|
|
||||||
// create payment to get authorization Id
|
// create payment to get authorization Id
|
||||||
$authId = createAuthorization();
|
$authId = createAuthorization($apiContext);
|
||||||
|
|
||||||
$amt = new Amount();
|
$amt = new Amount();
|
||||||
$amt->setCurrency("USD");
|
$amt->setCurrency("USD");
|
||||||
@@ -24,7 +27,6 @@ $amt->setTotal("1.00");
|
|||||||
|
|
||||||
### Capture
|
### Capture
|
||||||
$captur = new Capture();
|
$captur = new Capture();
|
||||||
$captur->setId($authId);
|
|
||||||
$captur->setAmount($amt);
|
$captur->setAmount($amt);
|
||||||
|
|
||||||
// get the authorization
|
// get the authorization
|
||||||
@@ -48,14 +50,17 @@ try {
|
|||||||
|
|
||||||
|
|
||||||
$refund = new Refund();
|
$refund = new Refund();
|
||||||
$refund->setId($capt->getId());
|
|
||||||
$refund->setAmount($amt);
|
$refund->setAmount($amt);
|
||||||
|
|
||||||
|
|
||||||
$capture = Capture::get($capt->getId(), $apiContext);
|
$capture = Capture::get($capt->getId(), $apiContext);
|
||||||
|
|
||||||
|
// create new API context
|
||||||
|
$context = new ApiContext(new OAuthTokenCredential(
|
||||||
|
'Aer9WxCa2q0dlmoyWv2n__xE10ttwuXL3pNLzLFU30atoUda5bKGh_lUqSzy',
|
||||||
|
'EIUvhhC4ga-Fy5N7vIZPRBOpcdoi2iVRhTwJ_ZhMD9RdZZSMtSGSNLAwq-ND'));
|
||||||
try {
|
try {
|
||||||
// (See bootstrap.php for more on `ApiContext`)
|
// (See bootstrap.php for more on `ApiContext`)
|
||||||
$captureRefund = $capture->refund($refund, $apiContext);
|
$captureRefund = $capture->refund($refund, $context);
|
||||||
} catch (\PPConnectionException $ex) {
|
} catch (\PPConnectionException $ex) {
|
||||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||||
var_dump($ex->getData());
|
var_dump($ex->getData());
|
||||||
@@ -71,7 +76,7 @@ try {
|
|||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
<?php
|
<?php
|
||||||
function createAuthorization()
|
function createAuthorization($apiContext)
|
||||||
{
|
{
|
||||||
$addr = new Address();
|
$addr = new Address();
|
||||||
$addr->setLine1("3909 Witmer Road");
|
$addr->setLine1("3909 Witmer Road");
|
||||||
@@ -101,7 +106,7 @@ function createAuthorization()
|
|||||||
|
|
||||||
$amount = new Amount();
|
$amount = new Amount();
|
||||||
$amount->setCurrency("USD");
|
$amount->setCurrency("USD");
|
||||||
$amount->setTotal("1.00");
|
$amount->setTotal("10.00");
|
||||||
|
|
||||||
$transaction = new Transaction();
|
$transaction = new Transaction();
|
||||||
$transaction->setAmount($amount);
|
$transaction->setAmount($amount);
|
||||||
@@ -112,7 +117,7 @@ function createAuthorization()
|
|||||||
$payment->setPayer($payer);
|
$payment->setPayer($payer);
|
||||||
$payment->setTransactions(array($transaction));
|
$payment->setTransactions(array($transaction));
|
||||||
|
|
||||||
$paymnt = $payment->create();
|
$paymnt = $payment->create($apiContext);
|
||||||
$resArray = $paymnt->toArray();
|
$resArray = $paymnt->toArray();
|
||||||
|
|
||||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use PayPal\Api\FundingInstrument;
|
|||||||
use PayPal\Api\Transaction;
|
use PayPal\Api\Transaction;
|
||||||
|
|
||||||
// create payment to get authorization Id
|
// create payment to get authorization Id
|
||||||
$authId = createAuthorization();
|
$authId = createAuthorization($apiContext);
|
||||||
|
|
||||||
$authorization = Authorization::get($authId, $apiContext);
|
$authorization = Authorization::get($authId, $apiContext);
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ try {
|
|||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
<?php
|
<?php
|
||||||
function createAuthorization()
|
function createAuthorization($apiContext)
|
||||||
{
|
{
|
||||||
$addr = new Address();
|
$addr = new Address();
|
||||||
$addr->setLine1("3909 Witmer Road");
|
$addr->setLine1("3909 Witmer Road");
|
||||||
@@ -83,7 +83,7 @@ function createAuthorization()
|
|||||||
$payment->setPayer($payer);
|
$payment->setPayer($payer);
|
||||||
$payment->setTransactions(array($transaction));
|
$payment->setTransactions(array($transaction));
|
||||||
|
|
||||||
$paymnt = $payment->create();
|
$paymnt = $payment->create($apiContext);
|
||||||
$resArray = $paymnt->toArray();
|
$resArray = $paymnt->toArray();
|
||||||
|
|
||||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||||
|
|||||||
Reference in New Issue
Block a user