forked from LiveCarta/PayPal-PHP-SDK
More Vault API Samples
- Updated Samples for Vault APIs - Updated Payment Execute to be more verbose - Delete Plan Sample Update - Fixes #168
This commit is contained in:
@@ -15,10 +15,10 @@ use PayPal\Api\Plan;
|
||||
try {
|
||||
$result = $createdPlan->delete($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Deleted a Plan", "Plan", $plan->getId(), null, $ex);
|
||||
ResultPrinter::printError("Deleted a Plan", "Plan", $createdPlan->getId(), null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Deleted a Plan", "Plan", $plan->getId(), null, null);
|
||||
ResultPrinter::printResult("Deleted a Plan", "Plan", $createdPlan->getId(), null, null);
|
||||
|
||||
return $plan;
|
||||
return $createdPlan;
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
<?php
|
||||
|
||||
// #Execute Agreement
|
||||
// This is the second part of CreateAgreement Sample.
|
||||
// Use this call to execute an agreement after the buyer approves it
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
session_start();
|
||||
|
||||
// ## Approval Status
|
||||
// Determine if the user accepted or denied the request
|
||||
if (isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
|
||||
$token = $_GET['token'];
|
||||
|
||||
$agreement = new \PayPal\Api\Agreement();
|
||||
|
||||
try {
|
||||
// ## Execute Agreement
|
||||
// Execute the agreement by passing in the token
|
||||
$agreement->execute($token, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $ex);
|
||||
|
||||
@@ -204,7 +204,36 @@ 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": "ExecuteAgreement"
|
||||
},
|
||||
"depth": 2,
|
||||
"outline": []
|
||||
"outline": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Execute Agreement",
|
||||
"slug": "execute-agreement"
|
||||
},
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 2,
|
||||
"title": "Approval Status",
|
||||
"slug": "approval-status"
|
||||
},
|
||||
"depth": 2
|
||||
}, {
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 2,
|
||||
"title": "Execute Agreement",
|
||||
"slug": "execute-agreement"
|
||||
},
|
||||
"depth": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"type": "file",
|
||||
"data": {
|
||||
@@ -1914,7 +1943,26 @@ 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": "Execute Payment Sample",
|
||||
"slug": "execute-payment-sample"
|
||||
},
|
||||
"depth": 1
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Approval Status",
|
||||
"slug": "approval-status"
|
||||
},
|
||||
"depth": 3
|
||||
}, {
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Payment Execute",
|
||||
"slug": "payment-execute"
|
||||
},
|
||||
"depth": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}, {
|
||||
@@ -2330,6 +2378,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
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "file",
|
||||
"data": {
|
||||
"language": {
|
||||
"nameMatchers": [{}, ".fbp"],
|
||||
"pygmentsLexer": "php",
|
||||
"singleLineComment": ["//"],
|
||||
"ignorePrefix": "}",
|
||||
"foldPrefix": "^",
|
||||
"name": "PHP"
|
||||
},
|
||||
"sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/PayPal-PHP-SDK/sample/vault/CreateBankAccount.php",
|
||||
"projectPath": "vault/CreateBankAccount.php",
|
||||
"targetPath": "vault/CreateBankAccount",
|
||||
"pageTitle": "vault/CreateBankAccount",
|
||||
"title": "CreateBankAccount"
|
||||
},
|
||||
"depth": 2,
|
||||
"outline": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Create Bank Account Sample",
|
||||
"slug": "create-bank-account-sample"
|
||||
},
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Bank Account",
|
||||
"slug": "bank-account"
|
||||
},
|
||||
"depth": 3
|
||||
}, {
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Save bank account",
|
||||
"slug": "save-bank-account"
|
||||
},
|
||||
"depth": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"type": "file",
|
||||
"data": {
|
||||
"language": {
|
||||
@@ -2377,6 +2473,46 @@ 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
|
||||
]
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"type": "file",
|
||||
"data": {
|
||||
"language": {
|
||||
"nameMatchers": [{}, ".fbp"],
|
||||
"pygmentsLexer": "php",
|
||||
"singleLineComment": ["//"],
|
||||
"ignorePrefix": "}",
|
||||
"foldPrefix": "^",
|
||||
"name": "PHP"
|
||||
},
|
||||
"sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/PayPal-PHP-SDK/sample/vault/DeleteBankAccount.php",
|
||||
"projectPath": "vault/DeleteBankAccount.php",
|
||||
"targetPath": "vault/DeleteBankAccount",
|
||||
"pageTitle": "vault/DeleteBankAccount",
|
||||
"title": "DeleteBankAccount"
|
||||
},
|
||||
"depth": 2,
|
||||
"outline": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Delete Bank Account Sample",
|
||||
"slug": "delete-bank-account-sample"
|
||||
},
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 3,
|
||||
"title": "Delete Card",
|
||||
"slug": "delete-card"
|
||||
},
|
||||
"depth": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"type": "file",
|
||||
"data": {
|
||||
@@ -2417,6 +2553,35 @@ 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
|
||||
]
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"type": "file",
|
||||
"data": {
|
||||
"language": {
|
||||
"nameMatchers": [{}, ".fbp"],
|
||||
"pygmentsLexer": "php",
|
||||
"singleLineComment": ["//"],
|
||||
"ignorePrefix": "}",
|
||||
"foldPrefix": "^",
|
||||
"name": "PHP"
|
||||
},
|
||||
"sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/PayPal-PHP-SDK/sample/vault/GetBankAccount.php",
|
||||
"projectPath": "vault/GetBankAccount.php",
|
||||
"targetPath": "vault/GetBankAccount",
|
||||
"pageTitle": "vault/GetBankAccount",
|
||||
"title": "GetBankAccount"
|
||||
},
|
||||
"depth": 2,
|
||||
"outline": [
|
||||
{
|
||||
"type": "heading",
|
||||
"data": {
|
||||
"level": 1,
|
||||
"title": "Get Bank Account Sample",
|
||||
"slug": "get-bank-account-sample"
|
||||
},
|
||||
"depth": 1
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"type": "file",
|
||||
"data": {
|
||||
|
||||
@@ -9,10 +9,10 @@ API used: /v1/payments/billing-plans</p></div></div></div><div class="segment"><
|
||||
<span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$result</span> = <span class="hljs-variable">$createdPlan</span>->delete(<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">"Deleted a Plan"</span>, <span class="hljs-string">"Plan"</span>, <span class="hljs-variable">$plan</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
ResultPrinter::printError(<span class="hljs-string">"Deleted a Plan"</span>, <span class="hljs-string">"Plan"</span>, <span class="hljs-variable">$createdPlan</span>->getId(), <span class="hljs-keyword">null</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">"Deleted a Plan"</span>, <span class="hljs-string">"Plan"</span>, <span class="hljs-variable">$plan</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>);
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Deleted a Plan"</span>, <span class="hljs-string">"Plan"</span>, <span class="hljs-variable">$createdPlan</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$plan</span>;</div></div></div></div></body></html>
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$createdPlan</span>;</div></div></div></div></body></html>
|
||||
@@ -1,15 +1,12 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>billing/ExecuteAgreement</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="billing/ExecuteAgreement"><meta name="groc-project-path" content="billing/ExecuteAgreement.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">billing/ExecuteAgreement.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span>
|
||||
|
||||
<span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
session_start();
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>]) && <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>] == <span class="hljs-string">'true'</span>) {
|
||||
<!DOCTYPE html><html lang="en"><head><title>billing/ExecuteAgreement</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="billing/ExecuteAgreement"><meta name="groc-project-path" content="billing/ExecuteAgreement.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">billing/ExecuteAgreement.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="execute-agreement">Execute Agreement</h1>
|
||||
<p>This is the second part of CreateAgreement Sample.
|
||||
Use this call to execute an agreement after the buyer approves it</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h2 id="approval-status">Approval Status</h2>
|
||||
<p>Determine if the user accepted or denied the request</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">if</span> (<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>]) && <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>] == <span class="hljs-string">'true'</span>) {
|
||||
|
||||
<span class="hljs-variable">$token</span> = <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'token'</span>];
|
||||
|
||||
<span class="hljs-variable">$agreement</span> = <span class="hljs-keyword">new</span> \PayPal\Api\Agreement();
|
||||
|
||||
<span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$agreement</span>->execute(<span class="hljs-variable">$token</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h2 id="execute-agreement">Execute Agreement</h2>
|
||||
<p>Execute the agreement by passing in the token</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$agreement</span>->execute(<span class="hljs-variable">$token</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">"Executed an Agreement"</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-variable">$agreement</span>->getId(), <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'token'</span>], <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
|
||||
@@ -7,7 +7,7 @@ API used: /v1/payments/billing-agreements/<Agreement-Id></p></div></div></div><d
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Agreement</span>;
|
||||
|
||||
<span class="hljs-keyword">try</span> {
|
||||
<span class="hljs-variable">$agreement</span> = Agreement::get(<span class="hljs-string">'I-NH3BT1XF0G93'</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
<span class="hljs-variable">$agreement</span> = Agreement::get(<span class="hljs-variable">$createdAgreement</span>->getId(), <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">"Retrieved an Agreement"</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-variable">$agreement</span>->getId(), <span class="hljs-variable">$createdAgreement</span>->getId(), <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/ExecutePayment</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="payments/ExecutePayment"><meta name="groc-project-path" content="payments/ExecutePayment.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">payments/ExecutePayment.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="execute-payment-sample">Execute Payment Sample</h1>
|
||||
<p>This sample shows how you can complete
|
||||
a payment that has been approved by
|
||||
<p>This is the second step required to complete
|
||||
PayPal checkout. Once user completes the payment, paypal
|
||||
redirects the browser to "redirectUrl" provided in the request.
|
||||
This sample will show you how to execute the payment
|
||||
that has been approved by
|
||||
the buyer by logging into paypal site.
|
||||
You can optionally update transaction
|
||||
information by passing in one or more transactions.
|
||||
API used: POST '/v1/payments/payment/<payment-id>/execute'.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">ExecutePayment</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payment</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">PaymentExecution</span>;
|
||||
|
||||
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>]) && <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>] == <span class="hljs-string">'true'</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Get the payment Object by passing paymentId
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">PaymentExecution</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="approval-status">Approval Status</h3>
|
||||
<p>Determine if the user approved the payment or not</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">if</span> (<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>]) && <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>] == <span class="hljs-string">'true'</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Get the payment Object by passing paymentId
|
||||
payment id was previously stored in session in
|
||||
CreatePaymentUsingPayPal.php</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$paymentId</span> = <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'paymentId'</span>];
|
||||
<span class="hljs-variable">$payment</span> = Payment::get(<span class="hljs-variable">$paymentId</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>PaymentExecution object includes information necessary
|
||||
<span class="hljs-variable">$payment</span> = Payment::get(<span class="hljs-variable">$paymentId</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payment-execute">Payment Execute</h3>
|
||||
<p>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</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$execution</span> = <span class="hljs-keyword">new</span> PaymentExecution();
|
||||
<span class="hljs-variable">$execution</span>->setPayerId(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'PayerID'</span>]);
|
||||
|
||||
<span class="hljs-comment">//Execute the payment</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-variable">$result</span> = <span class="hljs-variable">$payment</span>->execute(<span class="hljs-variable">$execution</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
<span class="hljs-variable">$execution</span>->setPayerId(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'PayerID'</span>]);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Execute the payment
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$result</span> = <span class="hljs-variable">$payment</span>->execute(<span class="hljs-variable">$execution</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Executed Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-variable">$payment</span>->getId(), <span class="hljs-variable">$execution</span>, <span class="hljs-variable">$result</span>);
|
||||
|
||||
|
||||
68
sample/doc/vault/CreateBankAccount.html
Normal file
68
sample/doc/vault/CreateBankAccount.html
Normal file
@@ -0,0 +1,68 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>vault/CreateBankAccount</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/CreateBankAccount"><meta name="groc-project-path" content="vault/CreateBankAccount.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/CreateBankAccount.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="create-bank-account-sample">Create Bank Account Sample</h1>
|
||||
<p>You can store credit card details securely
|
||||
with PayPal. You can then use the returned
|
||||
Bank Account id to process future payments.
|
||||
API used: POST /v1/vault/bank-accounts</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">BankAccount</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="bank-account">Bank Account</h3>
|
||||
<p>A resource representing a bank account that is
|
||||
to be stored with PayPal.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/*
|
||||
{
|
||||
"account_number": "4417119669820331",
|
||||
"account_number_type": "IBAN",
|
||||
"account_type": "SAVINGS",
|
||||
"account_name": "Ramraj",
|
||||
"check_type": "PERSONAL",
|
||||
"auth_type": "WEB",
|
||||
"bank_name": "CITI",
|
||||
"country_code": "US",
|
||||
"first_name": "Ramraj",
|
||||
"last_name": "K",
|
||||
"birth_date": "1987-08-13",
|
||||
"billing_address": {
|
||||
"line1": "52 N Main ST",
|
||||
"city": "Johnstown",
|
||||
"country_code": "US",
|
||||
"postal_code": "43210",
|
||||
"state": "OH",
|
||||
"phone": "408-334-8890"
|
||||
},
|
||||
"external_customer_id": "external_id"
|
||||
}
|
||||
*/</span>
|
||||
<span class="hljs-variable">$bankAccount</span> = <span class="hljs-keyword">new</span> BankAccount();
|
||||
<span class="hljs-variable">$bankAccount</span>->setAccountNumber(<span class="hljs-string">"4417119669820331"</span>)
|
||||
->setAccountNumberType(<span class="hljs-string">"IBAN"</span>)
|
||||
->setAccountType(<span class="hljs-string">"SAVINGS"</span>)
|
||||
->setAccountName(<span class="hljs-string">"Ramraj"</span>)
|
||||
->setCheckType(<span class="hljs-string">"PERSONAL"</span>)
|
||||
->setAuthType(<span class="hljs-string">"WEB"</span>)
|
||||
->setBankName(<span class="hljs-string">"CITI"</span>)
|
||||
->setCountryCode(<span class="hljs-string">"US"</span>)
|
||||
->setFirstName(<span class="hljs-string">"Ramraj"</span>)
|
||||
->setLastName(<span class="hljs-string">"K"</span>)
|
||||
->setBirthDate(<span class="hljs-string">"1987-08-13"</span>)
|
||||
->setExternalCustomerId(uniqid());
|
||||
|
||||
<span class="hljs-variable">$billingAddress</span> = <span class="hljs-keyword">new</span> \PayPal\Api\Address();
|
||||
<span class="hljs-variable">$billingAddress</span>->setLine1(<span class="hljs-string">"52 N Main St"</span>)
|
||||
->setCity(<span class="hljs-string">"Johnstown"</span>)
|
||||
->setState(<span class="hljs-string">"OH"</span>)
|
||||
->setCountryCode(<span class="hljs-string">"US"</span>)
|
||||
->setPostalCode(<span class="hljs-string">"43210"</span>)
|
||||
->setPhone(<span class="hljs-string">"408-334-8890"</span>);
|
||||
|
||||
<span class="hljs-variable">$bankAccount</span>->setBillingAddress(<span class="hljs-variable">$billingAddress</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$bankAccount</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="save-bank-account">Save bank account</h3>
|
||||
<p>Creates the bank account as a resource
|
||||
in the PayPal vault. The response contains
|
||||
an 'id' that you can use to refer to it
|
||||
in future payments.
|
||||
(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">$bankAccount</span>->create(<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">"Create Bank Account"</span>, <span class="hljs-string">"Bank Account"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</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">"Create Bank Account"</span>, <span class="hljs-string">"Bank Account"</span>, <span class="hljs-variable">$bankAccount</span>->getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$bankAccount</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$bankAccount</span>;</div></div></div></div></body></html>
|
||||
16
sample/doc/vault/DeleteBankAccount.html
Normal file
16
sample/doc/vault/DeleteBankAccount.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>vault/DeleteBankAccount</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/DeleteBankAccount"><meta name="groc-project-path" content="vault/DeleteBankAccount.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/DeleteBankAccount.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="delete-bank-account-sample">Delete Bank Account Sample</h1>
|
||||
<p>This sample code demonstrate how you can
|
||||
delete a saved bank account
|
||||
API used: /v1/vault/bank-accounts/{<bankAccountId>}
|
||||
NOTE: HTTP method used here is DELETE</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> \PayPal\Api\BankAccount $card */</span>
|
||||
<span class="hljs-variable">$bankAccount</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateBankAccount.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="delete-card">Delete Card</h3>
|
||||
<p>Lookup and delete a saved credit card.
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$bankAccount</span>->delete(<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">"Delete Bank Account"</span>, <span class="hljs-string">"Bank Account"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</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">"Delete Bank Account"</span>, <span class="hljs-string">"Bank Account"</span>, <span class="hljs-variable">$bankAccount</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>);</div></div></div></div></body></html>
|
||||
@@ -8,12 +8,10 @@ NOTE: HTTP method used here is DELETE</p></div></div><div class="code"><div clas
|
||||
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="delete-card">Delete Card</h3>
|
||||
<p>Lookup and delete a saved credit card.
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$creditCard</span> = CreditCard::get(<span class="hljs-variable">$card</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
<span class="hljs-variable">$creditCard</span>->delete(<span class="hljs-variable">$apiContext</span>);
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$card</span>->delete(<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">"Delete Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</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">"Delete Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-variable">$card</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$creditCard</span>);</div></div></div></div></body></html>
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Delete Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-variable">$card</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>);</div></div></div></div></body></html>
|
||||
17
sample/doc/vault/GetBankAccount.html
Normal file
17
sample/doc/vault/GetBankAccount.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>vault/GetBankAccount</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/GetBankAccount"><meta name="groc-project-path" content="vault/GetBankAccount.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/GetBankAccount.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="get-bank-account-sample">Get Bank Account Sample</h1>
|
||||
<p>The Bank Account resource allows you to
|
||||
retrieve previously saved Bank Accounts.
|
||||
API called: '/v1/vault/bank-accounts'</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>The following code takes you through
|
||||
the process of retrieving a saved Bank Account</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/**<span class="hljs-phpdoc"> @var</span> \PayPal\Api\BankAccount $bankAccount */</span>
|
||||
<span class="hljs-variable">$bankAccount</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateBankAccount.php'</span>;
|
||||
|
||||
<span class="hljs-comment">/// ### Retrieve Bank Account</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">$bankAccount</span> = \PayPal\Api\BankAccount::get(<span class="hljs-variable">$bankAccount</span>->getId(), <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">"Get Bank Account"</span>, <span class="hljs-string">"Bank Account"</span>, <span class="hljs-variable">$bankAccount</span>->getId(), <span class="hljs-keyword">null</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">"Get Bank Account"</span>, <span class="hljs-string">"Bank Account"</span>, <span class="hljs-variable">$bankAccount</span>->getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$bankAccount</span>);
|
||||
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-variable">$bankAccount</span>;</div></div></div></div></body></html>
|
||||
@@ -5,6 +5,7 @@ API called: '/v1/vault/credit-card'
|
||||
The following code takes you through
|
||||
the process of retrieving 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>->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>;
|
||||
|
||||
|
||||
@@ -203,7 +203,35 @@ if (PHP_SAPI == 'cli') {
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-8"><h5>Direct credit card payments</h5></div>
|
||||
<div class="col-md-8"><h5>PayPal Payments - similar to Express Checkout in Classic APIs</small></h5>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<a href="payments/CreatePaymentUsingPayPal.php" class="btn btn-primary pull-left execute">
|
||||
Try It
|
||||
<i class="fa fa-play-circle-o"></i></a><a
|
||||
href="doc/payments/CreatePaymentUsingPayPal.html"
|
||||
class="btn btn-default pull-right">Source <i
|
||||
class="fa fa-file-code-o"></i></a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<h6>Step II: Execute after Success
|
||||
<small>(required step after user approval)</small></h6>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<a
|
||||
href="doc/payments/ExecutePayment.html"
|
||||
class="btn btn-default pull-right">Part II : 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>Payments using credit card information</h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="payments/CreatePayment.php" class="btn btn-primary pull-left execute"> Try It <i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
@@ -214,20 +242,7 @@ if (PHP_SAPI == 'cli') {
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-8"><h5>PayPal account payments</h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="payments/CreatePaymentUsingPayPal.php" class="btn btn-primary pull-left execute">
|
||||
Try It
|
||||
<i class="fa fa-play-circle-o"></i></a><a
|
||||
href="doc/payments/CreatePaymentUsingPayPal.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>Stored credit card payments</h5></div>
|
||||
<div class="col-md-8"><h5>Payments using saved credit card <small>(using Vault APIs)</small></h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="payments/CreatePaymentUsingSavedCard.php"
|
||||
class="btn btn-primary pull-left execute">
|
||||
@@ -504,6 +519,19 @@ if (PHP_SAPI == 'cli') {
|
||||
<i class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<h6>Step II: Execute after Success
|
||||
<small>(required step after user approval)</small></h6>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<a
|
||||
href="doc/billing/ExecuteAgreement.html"
|
||||
class="btn btn-default pull-right">Part II : Source <i
|
||||
class="fa fa-file-code-o"></i></a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
@@ -568,7 +596,7 @@ if (PHP_SAPI == 'cli') {
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-8"><h5>Save a credit card</h5></div>
|
||||
<div class="col-md-8"><h5>Credit Card - Save</h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="vault/CreateCreditCard.php" class="btn btn-primary pull-left execute"> Try It <i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
@@ -579,7 +607,7 @@ if (PHP_SAPI == 'cli') {
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-8"><h5>Retrieve saved credit card</h5></div>
|
||||
<div class="col-md-8"><h5>Credit Card - Retrieve</h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="vault/GetCreditCard.php" class="btn btn-primary pull-left execute"> Try It <i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
@@ -590,7 +618,7 @@ if (PHP_SAPI == 'cli') {
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-8"><h5>Delete saved credit card</h5></div>
|
||||
<div class="col-md-8"><h5>Credit Card - Delete</h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="vault/DeleteCreditCard.php" class="btn btn-primary pull-left execute"> Try It <i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
@@ -599,6 +627,39 @@ if (PHP_SAPI == 'cli') {
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-8"><h5>Bank Account - Save</h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="vault/CreateCreditCard.php" class="btn btn-primary pull-left execute"> Try It <i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/vault/CreateCreditCard.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>Bank Account - Retrieve</h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="vault/CreateBankAccount.php" class="btn btn-primary pull-left execute"> Try It <i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/vault/CreateBankAccount.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>Bank Account - Delete</h5></div>
|
||||
<div class="col-md-4">
|
||||
<a href="vault/DeleteBankAccount.php" class="btn btn-primary pull-left execute"> Try It <i
|
||||
class="fa fa-play-circle-o"></i></a>
|
||||
<a href="doc/vault/GetBankAccount.html" class="btn btn-default pull-right">Source <i
|
||||
class="fa fa-file-code-o"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
<?php
|
||||
// #Execute Payment Sample
|
||||
// This sample shows how you can complete
|
||||
// a payment that has been approved by
|
||||
// This is the second step required to complete
|
||||
// PayPal checkout. Once user completes the payment, paypal
|
||||
// redirects the browser to "redirectUrl" provided in the request.
|
||||
// This sample will show you how to execute the payment
|
||||
// that has been approved by
|
||||
// the buyer by logging into paypal site.
|
||||
// You can optionally update transaction
|
||||
// information by passing in one or more transactions.
|
||||
@@ -12,6 +15,8 @@ use PayPal\Api\ExecutePayment;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\PaymentExecution;
|
||||
|
||||
// ### Approval Status
|
||||
// Determine if the user approved the payment or not
|
||||
if (isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
|
||||
// Get the payment Object by passing paymentId
|
||||
@@ -20,6 +25,7 @@ if (isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
$paymentId = $_GET['paymentId'];
|
||||
$payment = Payment::get($paymentId, $apiContext);
|
||||
|
||||
// ### Payment Execute
|
||||
// PaymentExecution object includes information necessary
|
||||
// to execute a PayPal account payment.
|
||||
// The payer_id is added to the request query parameters
|
||||
@@ -27,7 +33,7 @@ if (isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
$execution = new PaymentExecution();
|
||||
$execution->setPayerId($_GET['PayerID']);
|
||||
|
||||
//Execute the payment
|
||||
// Execute the payment
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$result = $payment->execute($execution, $apiContext);
|
||||
|
||||
|
||||
81
sample/vault/CreateBankAccount.php
Normal file
81
sample/vault/CreateBankAccount.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
// # Create Bank Account Sample
|
||||
// You can store credit card details securely
|
||||
// with PayPal. You can then use the returned
|
||||
// Bank Account id to process future payments.
|
||||
// API used: POST /v1/vault/bank-accounts
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\BankAccount;
|
||||
|
||||
// ### Bank Account
|
||||
// A resource representing a bank account that is
|
||||
// to be stored with PayPal.
|
||||
/*
|
||||
{
|
||||
"account_number": "4417119669820331",
|
||||
"account_number_type": "IBAN",
|
||||
"account_type": "SAVINGS",
|
||||
"account_name": "Ramraj",
|
||||
"check_type": "PERSONAL",
|
||||
"auth_type": "WEB",
|
||||
"bank_name": "CITI",
|
||||
"country_code": "US",
|
||||
"first_name": "Ramraj",
|
||||
"last_name": "K",
|
||||
"birth_date": "1987-08-13",
|
||||
"billing_address": {
|
||||
"line1": "52 N Main ST",
|
||||
"city": "Johnstown",
|
||||
"country_code": "US",
|
||||
"postal_code": "43210",
|
||||
"state": "OH",
|
||||
"phone": "408-334-8890"
|
||||
},
|
||||
"external_customer_id": "external_id"
|
||||
}
|
||||
*/
|
||||
$bankAccount = new BankAccount();
|
||||
$bankAccount->setAccountNumber("4417119669820331")
|
||||
->setAccountNumberType("IBAN")
|
||||
->setAccountType("SAVINGS")
|
||||
->setAccountName("Ramraj")
|
||||
->setCheckType("PERSONAL")
|
||||
->setAuthType("WEB")
|
||||
->setBankName("CITI")
|
||||
->setCountryCode("US")
|
||||
->setFirstName("Ramraj")
|
||||
->setLastName("K")
|
||||
->setBirthDate("1987-08-13")
|
||||
->setExternalCustomerId(uniqid());
|
||||
|
||||
$billingAddress = new \PayPal\Api\Address();
|
||||
$billingAddress->setLine1("52 N Main St")
|
||||
->setCity("Johnstown")
|
||||
->setState("OH")
|
||||
->setCountryCode("US")
|
||||
->setPostalCode("43210")
|
||||
->setPhone("408-334-8890");
|
||||
|
||||
$bankAccount->setBillingAddress($billingAddress);
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $bankAccount;
|
||||
|
||||
// ### Save bank account
|
||||
// Creates the bank account as a resource
|
||||
// in the PayPal vault. The response contains
|
||||
// an 'id' that you can use to refer to it
|
||||
// in future payments.
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$bankAccount->create($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Create Bank Account", "Bank Account", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Create Bank Account", "Bank Account", $bankAccount->getId(), $request, $bankAccount);
|
||||
|
||||
return $bankAccount;
|
||||
21
sample/vault/DeleteBankAccount.php
Normal file
21
sample/vault/DeleteBankAccount.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
// # Delete Bank Account Sample
|
||||
// This sample code demonstrate how you can
|
||||
// delete a saved bank account
|
||||
// API used: /v1/vault/bank-accounts/{<bankAccountId>}
|
||||
// NOTE: HTTP method used here is DELETE
|
||||
|
||||
/** @var \PayPal\Api\BankAccount $card */
|
||||
$bankAccount = require 'CreateBankAccount.php';
|
||||
|
||||
try {
|
||||
// ### Delete Card
|
||||
// Lookup and delete a saved credit card.
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$bankAccount->delete($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Delete Bank Account", "Bank Account", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Delete Bank Account", "Bank Account", $bankAccount->getId(), null, null);
|
||||
@@ -13,12 +13,10 @@ 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);
|
||||
$card->delete($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Delete Credit Card", "Credit Card", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Delete Credit Card", "Credit Card", $card->getId(), null, $creditCard);
|
||||
ResultPrinter::printResult("Delete Credit Card", "Credit Card", $card->getId(), null, null);
|
||||
|
||||
25
sample/vault/GetBankAccount.php
Normal file
25
sample/vault/GetBankAccount.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
// # Get Bank Account Sample
|
||||
// The Bank Account resource allows you to
|
||||
// retrieve previously saved Bank Accounts.
|
||||
// API called: '/v1/vault/bank-accounts'
|
||||
|
||||
// The following code takes you through
|
||||
// the process of retrieving a saved Bank Account
|
||||
|
||||
/** @var \PayPal\Api\BankAccount $bankAccount */
|
||||
$bankAccount = require 'CreateBankAccount.php';
|
||||
|
||||
/// ### Retrieve Bank Account
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$bankAccount = \PayPal\Api\BankAccount::get($bankAccount->getId(), $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Get Bank Account", "Bank Account", $bankAccount->getId(), null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult("Get Bank Account", "Bank Account", $bankAccount->getId(), null, $bankAccount);
|
||||
|
||||
return $bankAccount;
|
||||
@@ -8,6 +8,7 @@
|
||||
// the process of retrieving a saved CreditCard
|
||||
/** @var CreditCard $card */
|
||||
$card = require 'CreateCreditCard.php';
|
||||
$id = $card->getId();
|
||||
|
||||
use PayPal\Api\CreditCard;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user