From aa1dee57a6eacbdf19a739d7b48f31ec643f4bb4 Mon Sep 17 00:00:00 2001 From: Ganesh Hegde <1ganesh1@facebook.com> Date: Wed, 29 May 2013 18:02:32 +0530 Subject: [PATCH] updated code comments to reflect on groc docs --- sample/payments/RefundCapture.php | 12 ++- sample/source/AuthorizationCapture.html | 92 +++++++++++++++++++++ sample/source/DeleteCreditCard.html | 53 ++++++++++++ sample/source/GetAuthorization.html | 81 ++++++++++++++++++ sample/source/GetCapture.html | 98 ++++++++++++++++++++++ sample/source/RefundCapture.html | 104 ++++++++++++++++++++++++ sample/source/VoidAuthorization.html | 82 +++++++++++++++++++ sample/vault/DeleteCreditCard.php | 14 ++-- 8 files changed, 523 insertions(+), 13 deletions(-) create mode 100644 sample/source/AuthorizationCapture.html create mode 100644 sample/source/DeleteCreditCard.html create mode 100644 sample/source/GetAuthorization.html create mode 100644 sample/source/GetCapture.html create mode 100644 sample/source/RefundCapture.html create mode 100644 sample/source/VoidAuthorization.html diff --git a/sample/payments/RefundCapture.php b/sample/payments/RefundCapture.php index 983e6b6..8c3583a 100644 --- a/sample/payments/RefundCapture.php +++ b/sample/payments/RefundCapture.php @@ -1,4 +1,9 @@ }/refund require __DIR__ . '/../bootstrap.php'; use PayPal\Api\Capture; use PayPal\Api\Refund; @@ -37,13 +42,6 @@ try { exit(1); } -// # Refund Capture Sample -// This sample code demonstrate how you can -// process a refund on a Captured transaction created -// using the Capture API. -// API used: /v1/payments/capture/{}/refund - - // ### Refund // Create a refund object indicating // refund amount diff --git a/sample/source/AuthorizationCapture.html b/sample/source/AuthorizationCapture.html new file mode 100644 index 0000000..6f964db --- /dev/null +++ b/sample/source/AuthorizationCapture.html @@ -0,0 +1,92 @@ +AuthorizationCaptureBack
<?php

AuthorizationCapture

+ +

This sample code demonstrate how you can capture the authorized payment +API used: /v1/payments/payment

require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\Capture; +use PayPal\Api\Authorization; +use PayPal\Api\Address; +use PayPal\Api\Amount; +use PayPal\Api\CreditCard; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\FundingInstrument; +use PayPal\Api\Transaction;

create payment to get authorization Id

$authId = createAuthorization(); + +$amt = new Amount(); +$amt->setCurrency("USD"); +$amt->setTotal("1.00"); + +### Capture +$captur = new Capture(); +$captur->setId($authId); +$captur->setAmount($amt);

get the authorization

$authorization = Authorization::get($authId, $apiContext);

Capture Payment

+ +

Capture Payment by posting to the APIService +using a valid ApiContext (See bootstrap.php for more on ApiContext) +The return object contains the status;

try { + $capt = $authorization->capture($captur, $apiContext); +} catch (\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} +?> +<html> +<body> + <div> + Capture payment: + <?php echo $capt->getId();?> + </div> + <pre> + <?php var_dump($capt->toArray());?> + </pre> + <a href='../index.html'>Back</a> +</body> +</html> +<?php +function createAuthorization() +{ + $addr = new Address(); + $addr->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"); + + $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); + + $fi = new FundingInstrument(); + $fi->setCredit_card($card); + + $payer = new Payer(); + $payer->setPayment_method("credit_card"); + $payer->setFunding_instruments(array($fi)); + + $amount = new Amount(); + $amount->setCurrency("USD"); + $amount->setTotal("1.00"); + + $transaction = new Transaction(); + $transaction->setAmount($amount); + $transaction->setDescription("This is the payment description."); + + $payment = new Payment(); + $payment->setIntent("authorize"); + $payment->setPayer($payer); + $payment->setTransactions(array($transaction)); + + $paymnt = $payment->create(); + $resArray = $paymnt->toArray(); + + return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; +}
\ No newline at end of file diff --git a/sample/source/DeleteCreditCard.html b/sample/source/DeleteCreditCard.html new file mode 100644 index 0000000..b690aae --- /dev/null +++ b/sample/source/DeleteCreditCard.html @@ -0,0 +1,53 @@ +DeleteCreditCardBack
<?php

Delete CreditCard Sample

+ +

This sample code demonstrate how you can

//delete a saved creditcard

using the delete API. +API used: /v1/vault/credit-card/{} +NOTE: HTTP method used here is DELETE

require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\CreditCard; +use PayPal\Api\CreditCard; +use PayPal\Api\Address;

save card for demo

+ +

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");

Save card

+ +

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. +(See bootstrap.php for more on ApiContext)

try { + $res = $card->create($apiContext); +} catch (\PPConnectionException $ex) { + echo "Exception:" . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} + + +$creditCard = CreditCard::get($res->getId(), $apiContext); + +try {

Delete Card

+ +

deletes saved credit card +(See bootstrap.php for more on ApiContext)

$creditCard->delete($apiContext); +} catch (\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + exit(1); +} +?> + +<html> +<body> +<div>Delete CreditCard:</div> + <p> Credit Card deleted Successfully</p> + <a href='../index.html'>Back</a> +</body> +</html>
\ No newline at end of file diff --git a/sample/source/GetAuthorization.html b/sample/source/GetAuthorization.html new file mode 100644 index 0000000..513f5f6 --- /dev/null +++ b/sample/source/GetAuthorization.html @@ -0,0 +1,81 @@ +GetAuthorizationBack
<?php

GetAuthorization

+ +

This sample code demonstrate how you can get details of an authorized payment +API used: /v1/payments/authorization/<$authorizationId>

require __DIR__ . '/../bootstrap.php'; + +use PayPal\Api\Authorization; +use PayPal\Api\Address; +use PayPal\Api\Amount; +use PayPal\Api\CreditCard; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\FundingInstrument; +use PayPal\Api\Transaction;

create payment to get authorization Id

$authId = createAuthorization();

GetAuthorization

+ +

GetAuthorization by posting to the APIService +using a valid ApiContext (See bootstrap.php for more on ApiContext) +The return object contains the status;

try { + $authorization = Authorization::get($authId, $apiContext); +} catch (\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} +?> +<html> +<body> + <div> + Get Authorization: + <?php echo $authorization->getId();?> + </div> + <pre><?php var_dump($authorization->toArray());?></pre> + <a href='../index.html'>Back</a> +</body> +</html> +<?php +function createAuthorization() +{ + $addr = new Address(); + $addr->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"); + + $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); + + $fi = new FundingInstrument(); + $fi->setCredit_card($card); + + $payer = new Payer(); + $payer->setPayment_method("credit_card"); + $payer->setFunding_instruments(array($fi)); + + $amount = new Amount(); + $amount->setCurrency("USD"); + $amount->setTotal("1.00"); + + $transaction = new Transaction(); + $transaction->setAmount($amount); + $transaction->setDescription("This is the payment description."); + + $payment = new Payment(); + $payment->setIntent("authorize"); + $payment->setPayer($payer); + $payment->setTransactions(array($transaction)); + + $paymnt = $payment->create(); + $resArray = $paymnt->toArray(); + + return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; +}
\ No newline at end of file diff --git a/sample/source/GetCapture.html b/sample/source/GetCapture.html new file mode 100644 index 0000000..bcd6310 --- /dev/null +++ b/sample/source/GetCapture.html @@ -0,0 +1,98 @@ +GetCaptureBack
<?php

GetCapture

+ +

This sample code demonstrate how you can get the details of Captured Payment +API used: /v1/payments/capture/<$captureId>

require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\Capture; +use PayPal\Api\Address; +use PayPal\Api\Amount; +use PayPal\Api\CreditCard; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\FundingInstrument; +use PayPal\Api\Transaction;

create payment to get authorization Id

$authId = createAuthorization(); +$amt = new Amount(); +$amt->setCurrency("USD"); +$amt->setTotal("1.00"); + +### Capture +$captur = new Capture(); +$captur->setId($authId); +$captur->setAmount($amt);

get the authorization

$authorization = Authorization::get($authId, $apiContext);

Capture Payment

+ +

Capture Payment by posting to the APIService +using a valid ApiContext (See bootstrap.php for more on ApiContext) +The return object contains the status;

try { + $capt = $authorization->capture($captur, $apiContext); +} catch (\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +}

Get Capture

+ +

Get Capture by posting to the APIService +using a valid ApiContext (See bootstrap.php for more on ApiContext) +The return object contains the status;

try { + $capture = Capture::get($capt->getId(), $apiContext); +} catch (\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} +?> +<html> +<body> + <div> + Get Capture : + <?php echo $capture->getId();?> + </div> + <pre><?php var_dump($capture->toArray());?></pre> + <a href='../index.html'>Back</a> +</body> +</html> +<?php +function createAuthorization() +{ + $addr = new Address(); + $addr->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"); + + $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); + + $fi = new FundingInstrument(); + $fi->setCredit_card($card); + + $payer = new Payer(); + $payer->setPayment_method("credit_card"); + $payer->setFunding_instruments(array($fi)); + + $amount = new Amount(); + $amount->setCurrency("USD"); + $amount->setTotal("1.00"); + + $transaction = new Transaction(); + $transaction->setAmount($amount); + $transaction->setDescription("This is the payment description."); + + $payment = new Payment(); + $payment->setIntent("authorize"); + $payment->setPayer($payer); + $payment->setTransactions(array($transaction)); + + $paymnt = $payment->create(); + $resArray = $paymnt->toArray(); + + return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; +}
\ No newline at end of file diff --git a/sample/source/RefundCapture.html b/sample/source/RefundCapture.html new file mode 100644 index 0000000..7d0a43f --- /dev/null +++ b/sample/source/RefundCapture.html @@ -0,0 +1,104 @@ +RefundCaptureBack
<?php

Refund Capture Sample

+ +

This sample code demonstrate how you can +process a refund on a Captured transaction created +using the Capture API. +API used: /v1/payments/capture/{}/refund

require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\Capture; +use PayPal\Api\Refund; +use PayPal\Api\Address; +use PayPal\Api\Amount; +use PayPal\Api\CreditCard; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\FundingInstrument; +use PayPal\Api\Transaction;

create payment to get authorization Id

$authId = createAuthorization(); + +$amt = new Amount(); +$amt->setCurrency("USD"); +$amt->setTotal("1.00"); + +### Capture +$captur = new Capture(); +$captur->setId($authId); +$captur->setAmount($amt);

get the authorization

$authorization = Authorization::get($authId, $apiContext);

Capture Payment

+ +

Capture Payment by posting to the APIService +using a valid ApiContext (See bootstrap.php for more on ApiContext) +The return object contains the status;

try { + $capt = $authorization->capture($captur, $apiContext); +} catch (\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +}

Refund

+ +

Create a refund object indicating +refund amount

$refund = new Refund(); +$refund->setId($capt->getId()); +$refund->setAmount($amt); + + +$capture = Capture::get($capt->getId(), $apiContext); +try {

(See bootstrap.php for more on ApiContext)

$captureRefund = $capture->refund($refund, $apiContext); +} catch (\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} +?> + +<html> +<body> + <div>Refund Capture:</div> + <pre><?php var_dump($captureRefund);?></pre> + <a href='../index.html'>Back</a> +</body> +</html> +<?php +function createAuthorization() +{ + $addr = new Address(); + $addr->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"); + + $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); + + $fi = new FundingInstrument(); + $fi->setCredit_card($card); + + $payer = new Payer(); + $payer->setPayment_method("credit_card"); + $payer->setFunding_instruments(array($fi)); + + $amount = new Amount(); + $amount->setCurrency("USD"); + $amount->setTotal("1.00"); + + $transaction = new Transaction(); + $transaction->setAmount($amount); + $transaction->setDescription("This is the payment description."); + + $payment = new Payment(); + $payment->setIntent("authorize"); + $payment->setPayer($payer); + $payment->setTransactions(array($transaction)); + + $paymnt = $payment->create(); + $resArray = $paymnt->toArray(); + + return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; +}
\ No newline at end of file diff --git a/sample/source/VoidAuthorization.html b/sample/source/VoidAuthorization.html new file mode 100644 index 0000000..b091c04 --- /dev/null +++ b/sample/source/VoidAuthorization.html @@ -0,0 +1,82 @@ +VoidAuthorizationBack
<?php

VoidAuthorization

+ +

This sample code demonstrate how you can void an authorized payment +API used: /v1/payments/authorization/<{authorizationid}>/void"

require __DIR__ . '/../bootstrap.php'; + +use PayPal\Api\Authorization; +use PayPal\Api\Address; +use PayPal\Api\Amount; +use PayPal\Api\CreditCard; +use PayPal\Api\Payer; +use PayPal\Api\Payment; +use PayPal\Api\FundingInstrument; +use PayPal\Api\Transaction;

create payment to get authorization Id

$authId = createAuthorization(); + +$authorization = Authorization::get($authId, $apiContext);

VoidAuthorization

+ +

VoidAuthorization by posting to the APIService +using a valid ApiContext (See bootstrap.php for more on ApiContext) +The return object contains the status;

try { + $void = $authorization->void($apiContext); +} catch (\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} +?> +<html> +<body> + <div> + Void Authorization: + </div> + <pre><?php var_dump($void->toArray());?></pre> + <a href='../index.html'>Back</a> +</body> +</html> +<?php +function createAuthorization() +{ + $addr = new Address(); + $addr->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"); + + $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); + + $fi = new FundingInstrument(); + $fi->setCredit_card($card); + + $payer = new Payer(); + $payer->setPayment_method("credit_card"); + $payer->setFunding_instruments(array($fi)); + + $amount = new Amount(); + $amount->setCurrency("USD"); + $amount->setTotal("1.00"); + + $transaction = new Transaction(); + $transaction->setAmount($amount); + $transaction->setDescription("This is the payment description."); + + $payment = new Payment(); + $payment->setIntent("authorize"); + $payment->setPayer($payer); + $payment->setTransactions(array($transaction)); + + $paymnt = $payment->create(); + $resArray = $paymnt->toArray(); + + return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; +}
\ No newline at end of file diff --git a/sample/vault/DeleteCreditCard.php b/sample/vault/DeleteCreditCard.php index 0eed82c..33f9d84 100644 --- a/sample/vault/DeleteCreditCard.php +++ b/sample/vault/DeleteCreditCard.php @@ -1,4 +1,10 @@ } +// NOTE: HTTP method used here is DELETE require __DIR__ . '/../bootstrap.php'; use PayPal\Api\CreditCard; use PayPal\Api\CreditCard; @@ -31,16 +37,12 @@ try { exit(1); } -// # Delete CreditCard Sample -// This sample code demonstrate how you can -//delete a saved creditcard -// using the delete API. -// API used: /v1/vault/credit-card/{} -// NOTE: HTTP method used here is DELETE $creditCard = CreditCard::get($res->getId(), $apiContext); try { + // ### Delete Card + // deletes saved credit card // (See bootstrap.php for more on `ApiContext`) $creditCard->delete($apiContext); } catch (\PPConnectionException $ex) {