diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e687b2..fd0d180 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,11 @@ CHANGELOG ========= -V0.6.0 (April 25, 2013) +V0.6.0 (April 26, 2013) ----------------------- * Adding support for dynamic configuration of SDK (Upgrading sdk-core-php dependency to V1.4.0) + * Changing resource class methods to take an ApiContext argument instead of a OauthTokenCredential argument. V0.5.0 (March 07, 2013) ----------------------- diff --git a/lib/PayPal/Api/CreditCard.php b/lib/PayPal/Api/CreditCard.php index 0a47b5a..982f51f 100644 --- a/lib/PayPal/Api/CreditCard.php +++ b/lib/PayPal/Api/CreditCard.php @@ -237,8 +237,8 @@ class CreditCard extends Resource implements IResource { if($apiContext == null) { $apiContext = new ApiContext(self::$credential); } - $call = new \PPRestCall(); - $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'), + $call = new \PPRestCall($apiContext); + $json = $call->execute( array('PayPal\Rest\RestHandler'), "/v1/vault/credit-card", "POST", $payLoad); $this->fromJson($json); @@ -259,8 +259,8 @@ class CreditCard extends Resource implements IResource { if($apiContext == null) { $apiContext = new ApiContext(self::$credential); } - $call = new \PPRestCall(); - $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'), + $call = new \PPRestCall($apiContext); + $json = $call->execute( array('PayPal\Rest\RestHandler'), "/v1/vault/credit-card/$creditcardid", "GET", $payLoad); $ret = new CreditCard(); diff --git a/lib/PayPal/Api/Payment.php b/lib/PayPal/Api/Payment.php index 3492d32..7ea69ba 100644 --- a/lib/PayPal/Api/Payment.php +++ b/lib/PayPal/Api/Payment.php @@ -185,8 +185,8 @@ class Payment extends Resource implements IResource { if($apiContext == null) { $apiContext = new ApiContext(self::$credential); } - $call = new \PPRestCall(); - $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'), + $call = new \PPRestCall($apiContext); + $json = $call->execute( array('PayPal\Rest\RestHandler'), "/v1/payments/payment?" . http_build_query(array_intersect_key($params, $allowedParams)), "GET", $payLoad); $ret = new PaymentHistory(); @@ -206,8 +206,8 @@ class Payment extends Resource implements IResource { if($apiContext == null) { $apiContext = new ApiContext(self::$credential); } - $call = new \PPRestCall(); - $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'), + $call = new \PPRestCall($apiContext); + $json = $call->execute( array('PayPal\Rest\RestHandler'), "/v1/payments/payment", "POST", $payLoad); $this->fromJson($json); @@ -228,8 +228,8 @@ class Payment extends Resource implements IResource { if($apiContext == null) { $apiContext = new ApiContext(self::$credential); } - $call = new \PPRestCall(); - $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'), + $call = new \PPRestCall($apiContext); + $json = $call->execute( array('PayPal\Rest\RestHandler'), "/v1/payments/payment/$paymentid", "GET", $payLoad); $ret = new Payment(); @@ -255,8 +255,8 @@ class Payment extends Resource implements IResource { if($apiContext == null) { $apiContext = new ApiContext(self::$credential); } - $call = new \PPRestCall(); - $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'), + $call = new \PPRestCall($apiContext); + $json = $call->execute( array('PayPal\Rest\RestHandler'), "/v1/payments/payment/{$this->getId()}/execute", "POST", $payLoad); $this->fromJson($json); diff --git a/lib/PayPal/Api/Refund.php b/lib/PayPal/Api/Refund.php index 89729ee..592fe4e 100644 --- a/lib/PayPal/Api/Refund.php +++ b/lib/PayPal/Api/Refund.php @@ -192,8 +192,8 @@ class Refund extends Resource implements IResource { if($apiContext == null) { $apiContext = new ApiContext(self::$credential); } - $call = new \PPRestCall(); - $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'), + $call = new \PPRestCall($apiContext); + $json = $call->execute( array('PayPal\Rest\RestHandler'), "/v1/payments/refund/$refundid", "GET", $payLoad); $ret = new Refund(); diff --git a/lib/PayPal/Api/Sale.php b/lib/PayPal/Api/Sale.php index bcb0619..4b431f4 100644 --- a/lib/PayPal/Api/Sale.php +++ b/lib/PayPal/Api/Sale.php @@ -144,8 +144,8 @@ class Sale extends Resource implements IResource { if($apiContext == null) { $apiContext = new ApiContext(self::$credential); } - $call = new \PPRestCall(); - $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'), + $call = new \PPRestCall($apiContext); + $json = $call->execute( array('PayPal\Rest\RestHandler'), "/v1/payments/sale/$saleid", "GET", $payLoad); $ret = new Sale(); @@ -171,8 +171,8 @@ class Sale extends Resource implements IResource { if($apiContext == null) { $apiContext = new ApiContext(self::$credential); } - $call = new \PPRestCall(); - $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'), + $call = new \PPRestCall($apiContext); + $json = $call->execute( array('PayPal\Rest\RestHandler'), "/v1/payments/sale/{$this->getId()}/refund", "POST", $payLoad); $this->fromJson($json); diff --git a/lib/PayPal/Auth/OAuthTokenCredential.php b/lib/PayPal/Auth/OAuthTokenCredential.php index 96e49c7..e5d375d 100644 --- a/lib/PayPal/Auth/OAuthTokenCredential.php +++ b/lib/PayPal/Auth/OAuthTokenCredential.php @@ -49,14 +49,15 @@ class OAuthTokenCredential { */ public function __construct($clientId, $clientSecret) { $this->clientId = $clientId; - $this->clientSecret = $clientSecret; - $this->logger = new \PPLoggingManager(__CLASS__); + $this->clientSecret = $clientSecret; } /** * @return the accessToken */ - public function getAccessToken($config) { + public function getAccessToken($config) { + + $this->logger = new \PPLoggingManager(__CLASS__, $config); // Check if Access Token is not null and has not expired. // The API returns expiry time as a relative time unit // We use a buffer time when checking for token expiry to account diff --git a/sample/bootstrap.php b/sample/bootstrap.php index 3d8f23c..5095a03 100644 --- a/sample/bootstrap.php +++ b/sample/bootstrap.php @@ -1,50 +1,57 @@ -::setCredential($cred) calls that -// you see in the samples. -$cred = new OAuthTokenCredential( - $configManager->get('acct1.ClientId'), - $configManager->get('acct1.ClientSecret')); - - -/** - * ### getBaseUrl function - * // utility function that returns base url for - * // determining return/cancel urls - * @return string - */ -function getBaseUrl() { - - $protocol = 'http'; - if ($_SERVER['SERVER_PORT'] == 443 || (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')) { - $protocol .= 's'; - $protocol_port = $_SERVER['SERVER_PORT']; - } else { - $protocol_port = 80; - } - - $host = $_SERVER['HTTP_HOST']; - $port = $_SERVER['SERVER_PORT']; - $request = $_SERVER['PHP_SELF']; - return dirname($protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request); -} +if(!file_exists(__DIR__ .'/vendor/autoload.php')) { + echo "The 'vendor' folder is missing. You must run 'composer update' to resolve application dependencies.\nPlease see the README for more information.\n"; + exit(1); +} +require __DIR__ . '/vendor/autoload.php'; +define("PP_CONFIG_PATH", __DIR__); + +use PayPal\Rest\ApiContext; +use PayPal\Auth\OAuthTokenCredential; + +// ### Api Context +// Pass in a `PayPal\Rest\ApiContext` object to authenticate +// the call. You can also send a unique request id +// (that ensures idempotency). The SDK generates +// a request id if you do not pass one explicitly. +$apiContext = new ApiContext(new OAuthTokenCredential( + 'EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM', + 'EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM')); +// Uncomment this step if you want to use per request +// dynamic configuration instead of using sdk_config.ini +/* +$apiContext->setConfig(array( + 'mode' => 'sandbox', + 'http.ConnectionTimeOut' => 30, + 'log.LogEnabled' => true, + 'log.FileName' => '../PayPal.log', + 'log.LogLevel' => 'FINE' +)); +*/ + +/** + * ### getBaseUrl function + * // utility function that returns base url for + * // determining return/cancel urls + * @return string + */ +function getBaseUrl() { + + $protocol = 'http'; + if ($_SERVER['SERVER_PORT'] == 443 || (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')) { + $protocol .= 's'; + $protocol_port = $_SERVER['SERVER_PORT']; + } else { + $protocol_port = 80; + } + + $host = $_SERVER['HTTP_HOST']; + $port = $_SERVER['SERVER_PORT']; + $request = $_SERVER['PHP_SELF']; + return dirname($protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request); +} diff --git a/sample/payments/CreatePayment.php b/sample/payments/CreatePayment.php index 562a70d..258629f 100644 --- a/sample/payments/CreatePayment.php +++ b/sample/payments/CreatePayment.php @@ -1,111 +1,105 @@ -setLine1("3909 Witmer Road"); -$addr->setLine2("Niagara Falls"); -$addr->setCity("Niagara Falls"); -$addr->setState("NY"); -$addr->setPostal_code("14305"); -$addr->setCountry_code("US"); -$addr->setPhone("716-298-1822"); - -// ### CreditCard -// A resource representing a credit card that can be -// used to fund a payment. -$card = new CreditCard(); -$card->setType("visa"); -$card->setNumber("4417119669820331"); -$card->setExpire_month("11"); -$card->setExpire_year("2019"); -$card->setCvv2("012"); -$card->setFirst_name("Joe"); -$card->setLast_name("Shopper"); -$card->setBilling_address($addr); - -// ### FundingInstrument -// A resource representing a Payer's funding instrument. -// Use a Payer ID (A unique identifier of the payer generated -// and provided by the facilitator. This is required when -// creating or using a tokenized funding instrument) -// and the `CreditCardDetails` -$fi = new FundingInstrument(); -$fi->setCredit_card($card); - -// ### Payer -// A resource representing a Payer that funds a payment -// Use the List of `FundingInstrument` and the Payment Method -// as 'credit_card' -$payer = new Payer(); -$payer->setPayment_method("credit_card"); -$payer->setFunding_instruments(array($fi)); - -// ### Amount -// Let's you specify a payment amount. -$amount = new Amount(); -$amount->setCurrency("USD"); -$amount->setTotal("1.00"); - -// ### Transaction -// A transaction defines the contract of a -// payment - what is the payment for and who -// is fulfilling it. Transaction is created with -// a `Payee` and `Amount` types -$transaction = new Transaction(); -$transaction->setAmount($amount); -$transaction->setDescription("This is the payment description."); - -// ### Payment -// A Payment Resource; create one using -// the above types and intent as 'sale' -$payment = new Payment(); -$payment->setIntent("sale"); -$payment->setPayer($payer); -$payment->setTransactions(array($transaction)); - -// ### Api Context -// Pass in a `ApiContext` object to authenticate -// the call and to send a unique request id -// (that ensures idempotency). The SDK generates -// a request id if you do not pass one explicitly. -$apiContext = new ApiContext($cred, 'Request' . time()); - -// ### Create Payment -// Create a payment by posting to the APIService -// using a valid ApiContext -// The return object contains the status; -try { - $payment->create($apiContext); -} catch (\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); -} -?> - -
-toArray());?>- Back - - +setLine1("3909 Witmer Road"); +$addr->setLine2("Niagara Falls"); +$addr->setCity("Niagara Falls"); +$addr->setState("NY"); +$addr->setPostal_code("14305"); +$addr->setCountry_code("US"); +$addr->setPhone("716-298-1822"); + +// ### CreditCard +// A resource representing a credit card that can be +// used to fund a payment. +$card = new CreditCard(); +$card->setType("visa"); +$card->setNumber("4417119669820331"); +$card->setExpire_month("11"); +$card->setExpire_year("2019"); +$card->setCvv2("012"); +$card->setFirst_name("Joe"); +$card->setLast_name("Shopper"); +$card->setBilling_address($addr); + +// ### FundingInstrument +// A resource representing a Payer's funding instrument. +// Use a Payer ID (A unique identifier of the payer generated +// and provided by the facilitator. This is required when +// creating or using a tokenized funding instrument) +// and the `CreditCardDetails` +$fi = new FundingInstrument(); +$fi->setCredit_card($card); + +// ### Payer +// A resource representing a Payer that funds a payment +// Use the List of `FundingInstrument` and the Payment Method +// as 'credit_card' +$payer = new Payer(); +$payer->setPayment_method("credit_card"); +$payer->setFunding_instruments(array($fi)); + +// ### Amount +// Let's you specify a payment amount. +$amount = new Amount(); +$amount->setCurrency("USD"); +$amount->setTotal("1.00"); + +// ### Transaction +// A transaction defines the contract of a +// payment - what is the payment for and who +// is fulfilling it. Transaction is created with +// a `Payee` and `Amount` types +$transaction = new Transaction(); +$transaction->setAmount($amount); +$transaction->setDescription("This is the payment description."); + +// ### Payment +// A Payment Resource; create one using +// the above types and intent as 'sale' +$payment = new Payment(); +$payment->setIntent("sale"); +$payment->setPayer($payer); +$payment->setTransactions(array($transaction)); + + + +// ### Create Payment +// Create a payment by posting to the APIService +// using a valid ApiContext (See bootstrap.php for more on `ApiContext`) +// The return object contains the status; +try { + $payment->create($apiContext); +} catch (\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} +?> + + +
toArray());?>+ Back + + diff --git a/sample/payments/CreatePaymentUsingPayPal.php b/sample/payments/CreatePaymentUsingPayPal.php index 8467c15..e4cf904 100644 --- a/sample/payments/CreatePaymentUsingPayPal.php +++ b/sample/payments/CreatePaymentUsingPayPal.php @@ -1,93 +1,86 @@ -setPayment_method("paypal"); - -// ### Amount -// Let's you specify a payment amount. -$amount = new Amount(); -$amount->setCurrency("USD"); -$amount->setTotal("1.00"); - -// ### Transaction -// A transaction defines the contract of a -// payment - what is the payment for and who -// is fulfilling it. Transaction is created with -// a `Payee` and `Amount` types -$transaction = new Transaction(); -$transaction->setAmount($amount); -$transaction->setDescription("This is the payment description."); - -// ### Redirect urls -// Set the urls that the buyer must be redirected to after -// payment approval/ cancellation. -$baseUrl = getBaseUrl(); -$redirectUrls = new RedirectUrls(); -$redirectUrls->setReturn_url("$baseUrl/ExecutePayment.php?success=true"); -$redirectUrls->setCancel_url("$baseUrl/ExecutePayment.php?success=false"); - -// ### Payment -// A Payment Resource; create one using -// the above types and intent as 'sale' -$payment = new Payment(); -$payment->setIntent("sale"); -$payment->setPayer($payer); -$payment->setRedirect_urls($redirectUrls); -$payment->setTransactions(array($transaction)); - -// ### Api Context -// Pass in a `ApiContext` object to authenticate -// the call and to send a unique request id -// (that ensures idempotency). The SDK generates -// a request id if you do not pass one explicitly. -$apiContext = new ApiContext($cred, 'Request' . time()); - -// ### Create Payment -// Create a payment by posting to the APIService -// using a valid apiContext -// The return object contains the status and the -// url to which the buyer must be redirected to -// for payment approval -try { - $payment->create($apiContext); -} catch (\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); -} - -// ### Redirect buyer to paypal -// Retrieve buyer approval url from the `payment` object. -foreach($payment->getLinks() as $link) { - if($link->getRel() == 'approval_url') { - $redirectUrl = $link->getHref(); - } -} -// It is not really a great idea to store the payment id -// in the session. In a real world app, please store the -// payment id in a database. -$_SESSION['paymentId'] = $payment->getId(); -if(isset($redirectUrl)) { - header("Location: $redirectUrl"); - exit; -} +setPayment_method("paypal"); + +// ### Amount +// Let's you specify a payment amount. +$amount = new Amount(); +$amount->setCurrency("USD"); +$amount->setTotal("1.00"); + +// ### Transaction +// A transaction defines the contract of a +// payment - what is the payment for and who +// is fulfilling it. Transaction is created with +// a `Payee` and `Amount` types +$transaction = new Transaction(); +$transaction->setAmount($amount); +$transaction->setDescription("This is the payment description."); + +// ### Redirect urls +// Set the urls that the buyer must be redirected to after +// payment approval/ cancellation. +$baseUrl = getBaseUrl(); +$redirectUrls = new RedirectUrls(); +$redirectUrls->setReturn_url("$baseUrl/ExecutePayment.php?success=true"); +$redirectUrls->setCancel_url("$baseUrl/ExecutePayment.php?success=false"); + +// ### Payment +// A Payment Resource; create one using +// the above types and intent as 'sale' +$payment = new Payment(); +$payment->setIntent("sale"); +$payment->setPayer($payer); +$payment->setRedirect_urls($redirectUrls); +$payment->setTransactions(array($transaction)); + +// ### Create Payment +// Create a payment by posting to the APIService +// using a valid apiContext. +// (See bootstrap.php for more on `ApiContext`) +// The return object contains the status and the +// url to which the buyer must be redirected to +// for payment approval +try { + $payment->create($apiContext); +} catch (\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} + +// ### Redirect buyer to paypal +// Retrieve buyer approval url from the `payment` object. +foreach($payment->getLinks() as $link) { + if($link->getRel() == 'approval_url') { + $redirectUrl = $link->getHref(); + } +} +// It is not really a great idea to store the payment id +// in the session. In a real world app, please store the +// payment id in a database. +$_SESSION['paymentId'] = $payment->getId(); +if(isset($redirectUrl)) { + header("Location: $redirectUrl"); + exit; +} diff --git a/sample/payments/CreatePaymentUsingSavedCard.php b/sample/payments/CreatePaymentUsingSavedCard.php index 5994c7c..40c9bf6 100644 --- a/sample/payments/CreatePaymentUsingSavedCard.php +++ b/sample/payments/CreatePaymentUsingSavedCard.php @@ -1,96 +1,88 @@ -setCredit_card_id($creditCardId); - -// ### FundingInstrument -// A resource representing a Payer's funding instrument. -// Use a Payer ID (A unique identifier of the payer generated -// and provided by the facilitator. This is required when -// creating or using a tokenized funding instrument) -// and the `CreditCardDetails` -$fi = new FundingInstrument(); -$fi->setCredit_card_token($creditCardToken); - -// ### Payer -// A resource representing a Payer that funds a payment -// Use the List of `FundingInstrument` and the Payment Method -// as 'credit_card' -$payer = new Payer(); -$payer->setPayment_method("credit_card"); -$payer->setFunding_instruments(array($fi)); - -// ### Amount -// Let's you specify a payment amount. -$amount = new Amount(); -$amount->setCurrency("USD"); -$amount->setTotal("1.00"); - -// ### Transaction -// A transaction defines the contract of a -// payment - what is the payment for and who -// is fulfilling it. Transaction is created with -// a `Payee` and `Amount` types -$transaction = new Transaction(); -$transaction->setAmount($amount); -$transaction->setDescription("This is the payment description."); - -// ### Payment -// A Payment Resource; create one using -// the above types and intent as 'sale' -$payment = new Payment(); -$payment->setIntent("sale"); -$payment->setPayer($payer); -$payment->setTransactions(array($transaction)); - -// ### Api Context -// Pass in a `ApiContext` object to authenticate -// the call and to send a unique request id -// (that ensures idempotency). The SDK generates -// a request id if you do not pass one explicitly. -$apiContext = new ApiContext($cred, 'Request' . time()); - -// ###Create Payment -// Create a payment by posting to the APIService -// using a valid apiContext -// The return object contains the status; -try { - $payment->create($apiContext); -} catch (\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); -} -?> - - -
toArray());?>- Back - +setCredit_card_id($creditCardId); + +// ### FundingInstrument +// A resource representing a Payer's funding instrument. +// Use a Payer ID (A unique identifier of the payer generated +// and provided by the facilitator. This is required when +// creating or using a tokenized funding instrument) +// and the `CreditCardDetails` +$fi = new FundingInstrument(); +$fi->setCredit_card_token($creditCardToken); + +// ### Payer +// A resource representing a Payer that funds a payment +// Use the List of `FundingInstrument` and the Payment Method +// as 'credit_card' +$payer = new Payer(); +$payer->setPayment_method("credit_card"); +$payer->setFunding_instruments(array($fi)); + +// ### Amount +// Let's you specify a payment amount. +$amount = new Amount(); +$amount->setCurrency("USD"); +$amount->setTotal("1.00"); + +// ### Transaction +// A transaction defines the contract of a +// payment - what is the payment for and who +// is fulfilling it. Transaction is created with +// a `Payee` and `Amount` types +$transaction = new Transaction(); +$transaction->setAmount($amount); +$transaction->setDescription("This is the payment description."); + +// ### Payment +// A Payment Resource; create one using +// the above types and intent as 'sale' +$payment = new Payment(); +$payment->setIntent("sale"); +$payment->setPayer($payer); +$payment->setTransactions(array($transaction)); + +// ###Create Payment +// Create a payment by posting to the APIService +// (See bootstrap.php for more on `ApiContext`) +// The return object contains the status; +try { + $payment->create($apiContext); +} catch (\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} +?> + + +
toArray());?>+ Back + \ No newline at end of file diff --git a/sample/payments/ExecutePayment.php b/sample/payments/ExecutePayment.php index 45224fd..6827c99 100644 --- a/sample/payments/ExecutePayment.php +++ b/sample/payments/ExecutePayment.php @@ -1,47 +1,40 @@ -/execute'. - -require __DIR__ . '/../bootstrap.php'; -use PayPal\Api\ExecutePayment; -use PayPal\Api\Payment; -use PayPal\Api\PaymentExecution; -use PayPal\Rest\ApiContext; -session_start(); - -if(isset($_GET['success']) && $_GET['success'] == 'true') { - // ### Api Context - // Pass in a `ApiContext` object to authenticate - // the call and to send a unique request id - // (that ensures idempotency). The SDK generates - // a request id if you do not pass one explicitly. - $apiContext = new ApiContext($cred); - - // Get the payment Object by passing paymentId - // payment id was previously stored in session in - // CreatePaymentUsingPayPal.php - $paymentId = $_SESSION['paymentId']; - $payment = Payment::get($paymentId); - - // PaymentExecution object includes information necessary - // to execute a PayPal account payment. - // The payer_id is added to the request query parameters - // when the user is redirected from paypal back to your site - $execution = new PaymentExecution(); - $execution->setPayer_id($_GET['PayerID']); - - //Execute the payment - $payment->execute($execution, $apiContext); - - echo "
"; - var_dump($payment->toArray()); - echo "Back"; - -} else { - echo "User cancelled payment."; +/execute'. + +require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\ExecutePayment; +use PayPal\Api\Payment; +use PayPal\Api\PaymentExecution; +session_start(); +if(isset($_GET['success']) && $_GET['success'] == 'true') { + + // Get the payment Object by passing paymentId + // payment id was previously stored in session in + // CreatePaymentUsingPayPal.php + $paymentId = $_SESSION['paymentId']; + $payment = Payment::get($paymentId, $apiContext); + + // PaymentExecution object includes information necessary + // to execute a PayPal account payment. + // The payer_id is added to the request query parameters + // when the user is redirected from paypal back to your site + $execution = new PaymentExecution(); + $execution->setPayer_id($_GET['PayerID']); + + //Execute the payment + // (See bootstrap.php for more on `ApiContext`) + $payment->execute($execution, $apiContext); + + echo "
"; + var_dump($payment->toArray()); + echo "Back"; + +} else { + echo "User cancelled payment."; } \ No newline at end of file diff --git a/sample/payments/GetPayment.php b/sample/payments/GetPayment.php index 97415ca..288d49e 100644 --- a/sample/payments/GetPayment.php +++ b/sample/payments/GetPayment.php @@ -1,39 +1,36 @@ -getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); -} -?> - - -
toArray());?>- Back - +getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} +?> + + +
toArray());?>+ Back + \ No newline at end of file diff --git a/sample/payments/ListPayments.php b/sample/payments/ListPayments.php index c11396c..4f950c4 100644 --- a/sample/payments/ListPayments.php +++ b/sample/payments/ListPayments.php @@ -1,42 +1,37 @@ - 10, 'start_index' => 5)); -} catch (\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); -} -?> - - -
toArray());?>- Back - - + 10, 'start_index' => 5), $apiContext); +} catch (\PPConnectionException $ex) { + echo "Exception:" . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} +?> + + +
toArray());?>+ Back + + diff --git a/sample/sale/GetSale.php b/sample/sale/GetSale.php index 9ac1697..521f445 100644 --- a/sample/sale/GetSale.php +++ b/sample/sale/GetSale.php @@ -1,35 +1,30 @@ -getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); -} -?> - - -
Pass in a ApiContext object to authenticate
-the call and to send a unique request id
-(that ensures idempotency). The SDK generates
-a request id if you do not pass one explicitly.
Creates the credit card as a resource in the PayPal vault. The response contains an 'id' that you can use to refer to it -in the future payments.
ApiContext)This sample code demonstrate how you can process a payment with a credit card. -API used: /v1/payments/payment
Base Address object used as shipping or billing -address in a payment. [Optional]
A resource representing a credit card that can be -used to fund a payment.
A resource representing a Payer's funding instrument.
Use a Payer ID (A unique identifier of the payer generated
and provided by the facilitator. This is required when
creating or using a tokenized funding instrument)
-and the CreditCardDetails
CreditCardDetailsA resource representing a Payer that funds a payment
Use the List of FundingInstrument and the Payment Method
-as 'credit_card'
Let's you specify a payment amount.
Let's you specify a payment amount.
A transaction defines the contract of a
payment - what is the payment for and who
is fulfilling it. Transaction is created with
-a Payee and Amount types
Payee and Amount typesA Payment Resource; create one using -the above types and intent as 'sale'
Pass in a ApiContext object to authenticate
-the call and to send a unique request id
-(that ensures idempotency). The SDK generates
-a request id if you do not pass one explicitly.
Create a payment by posting to the APIService -using a valid ApiContext -The return object contains the status;
ApiContext)
+The return object contains the status;
CreditCard
A resource representing a credit card that can be -used to fund a payment.