forked from LiveCarta/PayPal-PHP-SDK
Removing Dependency from SDK Core Project
- Copied files required for Rest API SDK - Removed PPApiContext and directly connected APIContext with PPConfigManager - Removed duplicate data storage of configuration and credentials. - Code Style Fixes - Remove build.xml file as it is not required anymore - Updated the samples - Updated the documentations
This commit is contained in:
52
sample/doc/payments/RefundCapture.html
Normal file
52
sample/doc/payments/RefundCapture.html
Normal file
@@ -0,0 +1,52 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/RefundCapture</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/RefundCapture"><meta name="groc-project-path" content="sample/payments/RefundCapture.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">sample/payments/RefundCapture.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="refund-capture-sample">Refund Capture Sample</h1>
|
||||
<p>This sample code demonstrates how you can
|
||||
process a refund on a Captured transaction.
|
||||
API used: /v1/payments/capture/{<captureID>}/refund</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">Authorization</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Capture</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Refund</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Rest</span>\<span class="hljs-title">ApiContext</span>;
|
||||
|
||||
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a mock authorization to get authorization Id</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authId</span> = createAuthorization(<span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Get the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-variable">$authId</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="capture">Capture</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper">
|
||||
<span class="hljs-variable">$amt</span> = <span class="hljs-keyword">new</span> Amount();
|
||||
<span class="hljs-variable">$amt</span>->setCurrency(<span class="hljs-string">"USD"</span>)
|
||||
->setTotal(<span class="hljs-string">"1.00"</span>);
|
||||
</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a capture</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$captureInfo</span> = <span class="hljs-keyword">new</span> Capture();
|
||||
<span class="hljs-variable">$captureInfo</span>->setAmount(<span class="hljs-variable">$amt</span>);
|
||||
|
||||
<span class="hljs-variable">$capture</span> = <span class="hljs-variable">$authorization</span>->capture(<span class="hljs-variable">$captureInfo</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund">Refund</h3>
|
||||
<p>Create a refund object indicating
|
||||
refund amount and call the refund method</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$refund</span> = <span class="hljs-keyword">new</span> Refund();
|
||||
<span class="hljs-variable">$refund</span>->setAmount(<span class="hljs-variable">$amt</span>);
|
||||
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a new apiContext object so we send a new
|
||||
PayPal-Request-Id (idempotency) header for this resource</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$apiContext</span> = getApiContext();
|
||||
|
||||
<span class="hljs-variable">$captureRefund</span> = <span class="hljs-variable">$capture</span>->refund(<span class="hljs-variable">$refund</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Refund a captured payment</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Refund Capture:</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$captureRefund</span>->toJSON(JSON_PRETTY_PRINT);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
Reference in New Issue
Block a user