Updates to Sample Code

- Updated UI Presentation on samples
- Fixed Bugs
This commit is contained in:
japatel
2014-11-02 17:06:58 -06:00
parent 4d481ad104
commit 3c02790138
97 changed files with 904 additions and 1249 deletions

View File

@@ -15,12 +15,15 @@ use PayPal\Api\CreditCard;
// to be stored with PayPal.
$card = new CreditCard();
$card->setType("visa")
->setNumber("4417119669820331")
->setExpireMonth("11")
->setExpireYear("2019")
->setCvv2("012")
->setFirstName("Joe")
->setLastName("Shopper");
->setNumber("4417119669820331")
->setExpireMonth("11")
->setExpireYear("2019")
->setCvv2("012")
->setFirstName("Joe")
->setLastName("Shopper");
// For Sample Purposes Only.
$request = clone $card;
// ### Save card
// Creates the credit card as a resource
@@ -29,20 +32,12 @@ $card->setType("visa")
// in future payments.
// (See bootstrap.php for more on `ApiContext`)
try {
$card->create($apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) {
echo "Exception:" . $ex->getMessage() . PHP_EOL;
var_dump($ex->getData());
exit(1);
$card->create($apiContext);
} catch (Exception $ex) {
ResultPrinter::printError("Create Credit Card", "Credit Card", null, $request, $ex);
exit(1);
}
?>
<html>
<head>
<title>Save a credit card</title>
</head>
<body>
<div>Saved a new credit card with id: <?php echo $card->getId();?></div>
<pre><?php echo $card->toJSON(128);?></pre>
<a href='../index.html'>Back</a>
</body>
</html>
ResultPrinter::printResult("Create Credit Card", "Credit Card", $card->getId(), $request, $card);
return $card;

View File

@@ -5,53 +5,20 @@
// API used: /v1/vault/credit-card/{<creditCardId>}
// NOTE: HTTP method used here is DELETE
require __DIR__ . '/../bootstrap.php';
/** @var CreditCard $card */
$card = require 'CreateCreditCard.php';
use PayPal\Api\CreditCard;
// Store a mock card that can be deleted later.
// ### CreditCard
// A resource representing a credit card that can be
// used to fund a payment.
$card = new CreditCard();
$card->setType("visa")
->setNumber("4417119669820331")
->setExpireMonth("11")
->setExpireYear("2019")
->setCvv2("012")
->setFirstName("Joe")
->setLastName("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 later.
// (See bootstrap.php for more on `ApiContext`)
try {
$card = $card->create($apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) {
echo "Exception:" . $ex->getMessage() . PHP_EOL;
var_dump($ex->getData());
exit(1);
// ### Delete Card
// Lookup and delete a saved credit card.
// (See bootstrap.php for more on `ApiContext`)
$creditCard = CreditCard::get($card->getId(), $apiContext);
$creditCard->delete($apiContext);
} catch (Exception $ex) {
ResultPrinter::printError("Delete Credit Card", "Credit Card", null, null, $ex);
exit(1);
}
try {
// ### Delete Card
// Lookup and delete a saved credit card.
// (See bootstrap.php for more on `ApiContext`)
$creditCard = CreditCard::get($card->getId(), $apiContext);
$creditCard->delete($apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) {
echo "Exception: " . $ex->getMessage() . PHP_EOL;
exit(1);
}
?>
<html>
<head>
<title>Delete a saved credit card</title>
</head>
<body>
<p> Credit Card deleted Successfully</p>
<a href='../index.html'>Back</a>
</body>
</html>
ResultPrinter::printResult("Delete Credit Card", "Credit Card", $card->getId(), null, $creditCard);

View File

@@ -6,30 +6,20 @@
// API called: '/v1/vault/credit-card'
// The following code takes you through
// the process of retrieving a saved CreditCard
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\CreditCard;
/** @var CreditCard $card */
$card = require 'CreateCreditCard.php';
// The cardId can be obtained from a previous save credit
// card operation. Use $card->getId()
$cardId = "CARD-44D10970C24287906KRCTWNI";
use PayPal\Api\CreditCard;
/// ### Retrieve card
// (See bootstrap.php for more on `ApiContext`)
try {
$card = CreditCard::get($cardId, $apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) {
echo "Exception: " . $ex->getMessage() . PHP_EOL;
var_dump($ex->getData());
exit(1);
$card = CreditCard::get($card->getId(), $apiContext);
} catch (Exception $ex) {
ResultPrinter::printError("Get Credit Card", "Credit Card", $card->getId(), null, $ex);
exit(1);
}
?>
<html>
<head>
<title>Lookup a saved credit card</title>
</head>
<body>
<div>Retrieving saved credit card: <?php echo $cardId;?></div>
<pre><?php echo $card->toJSON(128);?></pre>
<a href='../index.html'>Back</a>
</body>
</html>
ResultPrinter::printResult("Get Credit Card", "Credit Card", $card->getId(), null, $card);
return $card;