forked from LiveCarta/PayPal-PHP-SDK
- 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
38 lines
4.7 KiB
HTML
38 lines
4.7 KiB
HTML
<!DOCTYPE html><html lang="en"><head><title>sale/RefundSale</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="sale/RefundSale"><meta name="groc-project-path" content="sample/sale/RefundSale.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/sale/RefundSale.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="sale-refund-sample">Sale Refund Sample</h1>
|
|
<p>This sample code demonstrate how you can
|
|
process a refund on a sale transaction created
|
|
using the Payments API.
|
|
API used: /v1/payments/sale/{sale-id}/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">Amount</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">Sale</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund-amount">Refund amount</h3>
|
|
<p>Includes both the refunded amount (to Payer)
|
|
and refunded fee (to Payee). Use the $amt->details
|
|
field to mention fees refund details.</p></div></div><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">'0.01'</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund-object">Refund object</h3></div></div></div><div class="segment"><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-variable">$saleId</span> = <span class="hljs-string">'3RM92092UW5126232'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="sale">Sale</h3>
|
|
<p>A sale transaction.
|
|
Create a Sale object with the
|
|
given sale transaction id.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$sale</span> = <span class="hljs-keyword">new</span> Sale();
|
|
<span class="hljs-variable">$sale</span>->setId(<span class="hljs-variable">$saleId</span>);
|
|
<span class="hljs-keyword">try</span> { </div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Refund the sale
|
|
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$sale</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 sale</title>
|
|
</head>
|
|
<body>
|
|
<div>Refunding sale id: <span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$saleId</span>;<span class="hljs-preprocessor">?></span></div>
|
|
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$sale</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> |