public function refund() { $logger = new PPLoggingManager('RefundTransaction'); // ## RefundTransactionReq $refundTransactionReq = new RefundTransactionReq(); $refundTransactionRequest = new RefundTransactionRequestType(); // Either the `transaction ID` or the `payer ID` must be specified. // PayerID is unique encrypted merchant identification number // For setting `payerId`, // `refundTransactionRequest.setPayerID("A9BVYX8XCR9ZQ");` // Unique identifier of the transaction to be refunded. $refundTransactionRequest->TransactionID = "1GF88795WC5643301"; // Type of refund you are making. It is one of the following values: // // * `Full` - Full refund (default). // * `Partial` - Partial refund. // * `ExternalDispute` - External dispute. (Value available since // version // 82.0) // * `Other` - Other type of refund. (Value available since version // 82.0) $refundTransactionRequest->RefundType = "Partial"; // `Refund amount`, which contains // // * `Currency Code` // * `Amount` // The amount is required if RefundType is Partial. // `Note: // If RefundType is Full, do not set the amount.` $amount = new BasicAmountType("USD", "1.00"); $refundTransactionRequest->Amount = $amount; $refundTransactionReq->RefundTransactionRequest = $refundTransactionRequest; // ## Creating service wrapper object // Creating service wrapper object to make API call and loading // configuration file for your credentials and endpoint $service = new PayPalAPIInterfaceServiceService(); try { // ## Making API call // Invoke the appropriate method corresponding to API in service // wrapper object $response = $service->RefundTransaction($refundTransactionReq); } catch (Exception $ex) { $logger->error("Error Message : " + $ex->getMessage()); } // ## Accessing response parameters // You can access the response parameters using getter methods in // response object as shown below // ### Success values if ($response->Ack == "Success") { // Unique transaction ID of the refund. $logger->log("Refund Transaction ID" . $response->RefundTransactionID); } else { $logger->error("API Error Message : " . $response->Errors[0]->LongMessage); } return $response; }
*/ $logger = new PPLoggingManager('RefundTransaction'); $refundReqest = new RefundTransactionRequestType(); if ($_REQUEST['amt'] != "" && strtoupper($_POST['refundType']) != "FULL") { $refundReqest->Amount = new BasicAmountType($_REQUEST['currencyID'], $_REQUEST['amt']); } $refundReqest->RefundType = $_REQUEST['refundType']; $refundReqest->TransactionID = $_REQUEST['transID']; $refundReqest->RefundSource = $_REQUEST['refundSource']; $refundReqest->Memo = $_REQUEST['memo']; $refundReqest->RetryUntil = $_REQUEST['retryUntil']; $refundReq = new RefundTransactionReq(); $refundReq->RefundTransactionRequest = $refundReqest; $paypalService = new PayPalAPIInterfaceServiceService(); try { /* wrap API method calls on the service object with a try catch */ $refundResponse = $paypalService->RefundTransaction($refundReq); } catch (Exception $ex) { include_once "../Error.php"; exit; } if (isset($refundResponse)) { echo "<table>"; echo "<tr><td>Ack :</td><td><div id='Ack'>{$refundResponse->Ack}</div> </td></tr>"; //echo "<tr><td>RefundStatus :</td><td><div id='RefundStatus'>$refundResponse->RefundInfo->RefundStatus</div> </td></tr>"; echo "</table>"; echo "<pre>"; print_r($refundResponse); echo "</pre>"; } require_once '../Response.php';
public function refund($transactionId, $refundAmount = NULL) { $logger = new PPLoggingManager('GetTransactionDetails'); //load transaction try { $transaction = $this->getTxnDetails($transactionId); } catch (Exception $ex) { $logger->error("Error Message : " + $ex->getMessage()); } if ($transaction->Ack == "Success") { $transactionCurrencyType = $transaction->PaymentTransactionDetails->PaymentInfo->GrossAmount->currencyID; $transactionAmount = $transaction->PaymentTransactionDetails->PaymentInfo->GrossAmount->value; $transactionStatus = $transaction->PaymentTransactionDetails->PaymentInfo->PaymentStatus; } else { $logger->error("Error retrieving txn : " + $transaction->Errors[0]->LongMessage); return FALSE; } //check status - only 'Completed' or 'Partially-Refunded' should //be attempted //For 'Partially-Refunded' status, there is no known way to get //the remaining amount, so we need to rely on the api to tell us //if the refundAmount is too much. if ($transactionStatus != "Completed" && $transactionStatus != "Partially-Refunded") { $logger->error("Cannot refund this transaction."); return FALSE; } //verify amt, determine if refund type if ($refundAmount === NULL) { $refundAmount = $transactionAmount; $refundType = 'Full'; } else { if ($refundAmount == $transactionAmount) { //still full refund $refundType = 'Full'; } else { if ($refundAmount < $transactionAmount) { //partial refund $refundType = 'Partial'; } else { //error $logger->error("Invalid refund amount"); return FALSE; } } } //do refund $refundTransactionReq = new RefundTransactionReq(); $refundTransactionRequest = new RefundTransactionRequestType(); $refundTransactionRequest->TransactionID = $transactionId; // Type of refund you are making. It is one of the following values: // // * `Full` - Full refund (default). // * `Partial` - Partial refund. // * `ExternalDispute` - External dispute. (Value available since // version // 82.0) // * `Other` - Other type of refund. (Value available since version // 82.0) $refundTransactionRequest->RefundType = $refundType; $amount = new BasicAmountType($transactionCurrencyType, $refundAmount); $refundTransactionRequest->Amount = $amount; $refundTransactionReq->RefundTransactionRequest = $refundTransactionRequest; $service = new PayPalAPIInterfaceServiceService(); try { $response = $service->RefundTransaction($refundTransactionReq); } catch (Exception $ex) { $logger->error("Error Message : " + $ex->getMessage()); } if ($response->Ack == "Success") { return $response; } else { $logger->error("Error Message : " + $response->Errors[0]->LongMessage); return FALSE; } }