Fixes to Credit Card Update in Vault APIs

- Updated Samples
- Fixes #233
This commit is contained in:
japatel
2015-02-03 13:10:32 -06:00
parent b28718027a
commit 0e9894b4c4
5 changed files with 354 additions and 78 deletions

View File

@@ -426,18 +426,20 @@ class CreditCard extends PayPalResourceModel
/**
* Update information in a previously saved card. Only the modified fields need to be passed in the request.
*
* @param PatchRequest $patchRequest
* @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
* @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
* @return CreditCard
*/
public function update($apiContext = null, $restCall = null)
public function update($patchRequest, $apiContext = null, $restCall = null)
{
ArgumentValidator::validate($this->getId(), "Id");
$payLoad = $this->toJSON();
ArgumentValidator::validate($patchRequest, 'patch');
$payload = $patchRequest->toJSON();
$json = self::executeCall(
"/v1/vault/credit-card/{$this->getId()}",
"PATCH",
$payLoad,
$payload,
null,
$apiContext,
$restCall

View File

@@ -48,7 +48,37 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
"pageTitle": "billing/CreateBillingAgreementWithPayPal",
"title": "CreateBillingAgreementWithPayPal"
},
"depth": 2
"depth": 2,
"outline": [
{
"type": "heading",
"data": {
"level": 1,
"title": "Create Billing Agreement with PayPal as Payment Source",
"slug": "create-billing-agreement-with-paypal-as-payment-source"
},
"depth": 1,
"children": [
{
"type": "heading",
"data": {
"level": 3,
"title": "Create Agreement",
"slug": "create-agreement"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Get redirect url",
"slug": "get-redirect-url"
},
"depth": 3
}
]
}
]
}, {
"type": "file",
"data": {
@@ -310,77 +340,7 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
"pageTitle": "invoice/CreateInvoice",
"title": "CreateInvoice"
},
"depth": 2,
"outline": [
{
"type": "heading",
"data": {
"level": 1,
"title": "Create Invoice Sample",
"slug": "create-invoice-sample"
},
"depth": 1,
"children": [
{
"type": "heading",
"data": {
"level": 3,
"title": "Invoice Info",
"slug": "invoice-info"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Merchant Info",
"slug": "merchant-info"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Address Information",
"slug": "address-information"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Billing Information",
"slug": "billing-information"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Items List",
"slug": "items-list"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Shipping Information",
"slug": "shipping-information"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Create Invoice",
"slug": "create-invoice"
},
"depth": 3
}
]
}
]
"depth": 2
}, {
"type": "file",
"data": {
@@ -1050,7 +1010,93 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
"pageTitle": "payments/CreatePaymentUsingPayPal",
"title": "CreatePaymentUsingPayPal"
},
"depth": 2
"depth": 2,
"outline": [
{
"type": "heading",
"data": {
"level": 1,
"title": "Create Payment using PayPal as payment method",
"slug": "create-payment-using-paypal-as-payment-method"
},
"depth": 1,
"children": [
{
"type": "heading",
"data": {
"level": 3,
"title": "Payer",
"slug": "payer"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Itemized information",
"slug": "itemized-information"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Additional payment details",
"slug": "additional-payment-details"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Amount",
"slug": "amount"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Transaction",
"slug": "transaction"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Redirect urls",
"slug": "redirect-urls"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Payment",
"slug": "payment"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Create Payment",
"slug": "create-payment"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Get redirect url",
"slug": "get-redirect-url"
},
"depth": 3
}
]
}
]
}, {
"type": "file",
"data": {
@@ -1294,7 +1340,56 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
"pageTitle": "payouts/CreateSinglePayout",
"title": "CreateSinglePayout"
},
"depth": 2
"depth": 2,
"outline": [
{
"type": "heading",
"data": {
"level": 1,
"title": "Create Single Synchronous Payout Sample",
"slug": "create-single-synchronous-payout-sample"
},
"depth": 1,
"children": [
{
"type": "heading",
"data": {
"level": 3,
"title": "NOTE:",
"slug": "note"
},
"depth": 3,
"children": [
{
"type": "heading",
"data": {
"level": 4,
"title": "Batch Header Instance",
"slug": "batch-header-instance"
},
"depth": 4
}, {
"type": "heading",
"data": {
"level": 4,
"title": "Sender Item",
"slug": "sender-item"
},
"depth": 4
}
]
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Create Payout",
"slug": "create-payout"
},
"depth": 3
}
]
}
]
}, {
"type": "file",
"data": {
@@ -1422,7 +1517,37 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
"pageTitle": "vault/CreateCreditCard",
"title": "CreateCreditCard"
},
"depth": 2
"depth": 2,
"outline": [
{
"type": "heading",
"data": {
"level": 1,
"title": "Create Credit Card Sample",
"slug": "create-credit-card-sample"
},
"depth": 1,
"children": [
{
"type": "heading",
"data": {
"level": 3,
"title": "CreditCard",
"slug": "creditcard"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Save card",
"slug": "save-card"
},
"depth": 3
}
]
}
]
}, {
"type": "file",
"data": {
@@ -1495,6 +1620,54 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3
"title": "GetCreditCard"
},
"depth": 2
}, {
"type": "file",
"data": {
"language": {
"nameMatchers": [{}, ".fbp"],
"pygmentsLexer": "php",
"singleLineComment": ["//"],
"ignorePrefix": "}",
"foldPrefix": "^",
"name": "PHP"
},
"sourcePath": "/Users/japatel/Documents/workspace/paypal/PayPal-PHP-SDK/sample/vault/UpdateCreditCard.php",
"projectPath": "vault/UpdateCreditCard.php",
"targetPath": "vault/UpdateCreditCard",
"pageTitle": "vault/UpdateCreditCard",
"title": "UpdateCreditCard"
},
"depth": 2,
"outline": [
{
"type": "heading",
"data": {
"level": 1,
"title": "Update Credit Card Sample",
"slug": "update-credit-card-sample"
},
"depth": 1,
"children": [
{
"type": "heading",
"data": {
"level": 3,
"title": "Patch Object",
"slug": "patch-object"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Another Patch Object",
"slug": "another-patch-object"
},
"depth": 3
}
]
}
]
}
]
}

View File

@@ -0,0 +1,39 @@
<!DOCTYPE html><html lang="en"><head><title>vault/UpdateCreditCard</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="vault/UpdateCreditCard"><meta name="groc-project-path" content="vault/UpdateCreditCard.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">vault/UpdateCreditCard.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="update-credit-card-sample">Update Credit Card Sample</h1>
<p>The CreditCard resource allows you to
update previously saved CreditCards.
API called: PATCH /v1/vault/credit-cards/<Credit-Card-Id>
The following code takes you through
the process of updating a saved CreditCard</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> CreditCard $card */</span>
<span class="hljs-variable">$card</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateCreditCard.php'</span>;
<span class="hljs-variable">$id</span> = <span class="hljs-variable">$card</span>-&gt;getId();
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">CreditCard</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Patch</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="patch-object">Patch Object</h3>
<p>You could update a credit card by sending patch requests. Each path object would have a specific detail in the object to be updated.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$pathOperation</span> = <span class="hljs-keyword">new</span> Patch();
<span class="hljs-variable">$pathOperation</span>-&gt;setOp(<span class="hljs-string">"replace"</span>)
-&gt;setPath(<span class="hljs-string">'/expire_month'</span>)
-&gt;setValue(<span class="hljs-string">"12"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="another-patch-object">Another Patch Object</h3>
<p>You could set more than one patch while updating a credit card.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$pathOperation2</span> = <span class="hljs-keyword">new</span> Patch();
<span class="hljs-variable">$pathOperation2</span>-&gt;setOp(<span class="hljs-string">'add'</span>)
-&gt;setPath(<span class="hljs-string">'/billing_address'</span>)
-&gt;setValue(json_decode(<span class="hljs-string">'{
"line1": "111 First Street",
"city": "Saratoga",
"country_code": "US",
"state": "CA",
"postal_code": "95070"
}'</span>));
<span class="hljs-variable">$pathRequest</span> = <span class="hljs-keyword">new</span> \PayPal\Api\PatchRequest();
<span class="hljs-variable">$pathRequest</span>-&gt;addPatch(<span class="hljs-variable">$pathOperation</span>)
-&gt;addPatch(<span class="hljs-variable">$pathOperation2</span>);
<span class="hljs-comment">/// ### Update Credit Card</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
<span class="hljs-variable">$card</span> = <span class="hljs-variable">$card</span>-&gt;update(<span class="hljs-variable">$pathRequest</span>, <span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
ResultPrinter::printError(<span class="hljs-string">"Updated Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-variable">$card</span>-&gt;getId(), <span class="hljs-variable">$pathRequest</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}
ResultPrinter::printResult(<span class="hljs-string">"Updated Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-variable">$card</span>-&gt;getId(), <span class="hljs-variable">$pathRequest</span>, <span class="hljs-variable">$card</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$card</span>;</div></div></div></div></body></html>

View File

@@ -754,6 +754,17 @@ if (PHP_SAPI == 'cli') {
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Credit Card - Update</h5></div>
<div class="col-md-4">
<a href="vault/UpdateCreditCard.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/vault/UpdateCreditCard.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Credit Card - Delete</h5></div>

View File

@@ -0,0 +1,51 @@
<?php
// # Update Credit Card Sample
// The CreditCard resource allows you to
// update previously saved CreditCards.
// API called: PATCH /v1/vault/credit-cards/<Credit-Card-Id>
// The following code takes you through
// the process of updating a saved CreditCard
/** @var CreditCard $card */
$card = require 'CreateCreditCard.php';
$id = $card->getId();
use PayPal\Api\CreditCard;
use PayPal\Api\Patch;
// ### Patch Object
// You could update a credit card by sending patch requests. Each path object would have a specific detail in the object to be updated.
$pathOperation = new Patch();
$pathOperation->setOp("replace")
->setPath('/expire_month')
->setValue("12");
// ### Another Patch Object
// You could set more than one patch while updating a credit card.
$pathOperation2 = new Patch();
$pathOperation2->setOp('add')
->setPath('/billing_address')
->setValue(json_decode('{
"line1": "111 First Street",
"city": "Saratoga",
"country_code": "US",
"state": "CA",
"postal_code": "95070"
}'));
$pathRequest = new \PayPal\Api\PatchRequest();
$pathRequest->addPatch($pathOperation)
->addPatch($pathOperation2);
/// ### Update Credit Card
// (See bootstrap.php for more on `ApiContext`)
try {
$card = $card->update($pathRequest, $apiContext);
} catch (Exception $ex) {
ResultPrinter::printError("Updated Credit Card", "Credit Card", $card->getId(), $pathRequest, $ex);
exit(1);
}
ResultPrinter::printResult("Updated Credit Card", "Credit Card", $card->getId(), $pathRequest, $card);
return $card;