Details including both refunded amount (to payer) and refunded fee (to payee). 10 characters max.
public setAmount ( |
||
$amount |
public function refundSale($saleId, $refundAmount, $currency = CurrencyConst::EURO) { $apiContext = $this->connectionService->getApiContext(); $amount = new Amount(); $amount->setCurrency($currency)->setTotal($refundAmount); $refund = new Refund(); $refund->setAmount($amount); $sale = new Sale(); $sale->setId($saleId); $refundSale = $sale->refund($refund, $apiContext); return $refundSale; }
/** * @group integration */ public function testOperations() { try { $authId = AuthorizationTest::authorize(); $auth = Authorization::get($authId); $amount = new Amount(); $amount->setCurrency("USD"); $amount->setTotal("1.00"); $captr = new Capture(); $captr->setId($authId); $captr->setAmount($amount); $capt = $auth->capture($captr); $captureId = $capt->getId(); $this->assertNotNull($captureId); $refund = new Refund(); $refund->setId($captureId); $refund->setAmount($amount); $capture = Capture::get($captureId); $this->assertNotNull($capture->getId()); $retund = $capture->refund($refund); $this->assertNotNull($retund->getId()); } catch (PayPalConnectionException $ex) { $this->markTestSkipped('Tests failing because of intermittent failures in Paypal Sandbox environment.' . $ex->getMessage()); } }
public static function createRefund() { $refund = new Refund(); $refund->setCreateTime(self::$createTime); $refund->setAmount(AmountTest::createAmount()); $refund->setCaptureId(self::$captureId); $refund->setId(self::$id); $refund->setLinks(array(LinksTest::getObject())); $refund->setParentPayment(self::$parentPayment); return $refund; }
public static function createRefund() { $refund = new Refund(); $refund->setAmount(AmountTest::createAmount()); $refund->setCapture_id(self::$captureId); $refund->setCreate_time(self::$createTime); $refund->setDescription(self::$description); $refund->setId(self::$id); $refund->setLinks(array(LinkTest::createLink())); $refund->setParent_payment(self::$parentPayment); return $refund; }
public function testOperations() { $payment = PaymentTest::createNewPayment(); $payment->create(); $transactions = $payment->getTransactions(); $resources = $transactions[0]->getRelated_resources(); $saleId = $resources[0]->getSale()->getId(); $sale = Sale::get($saleId); $this->assertNotNull($sale); $refund = new Refund(); $refund->setAmount(AmountTest::createAmount()); $sale->refund($refund); $this->setExpectedException('\\InvalidArgumentException'); $sale->refund(NULL); }
public function testOperations() { $authId = AuthorizationTest::authorize(); $auth = Authorization::get($authId); $amount = new Amount(); $amount->setCurrency("USD"); $amount->setTotal("1.00"); $captr = new Capture(); $captr->setId($authId); $captr->setAmount($amount); $capt = $auth->capture($captr); $captureId = $capt->getId(); $this->assertNotNull($captureId); $refund = new Refund(); $refund->setId($captureId); $refund->setAmount($amount); $capture = Capture::get($captureId); $this->assertNotNull($capture->getId()); $retund = $capture->refund($refund); $this->assertNotNull($retund->getId()); }
// API used: /v1/payments/sale/{sale-id}/refund /** @var Sale $sale */ $sale = (require 'GetSale.php'); $saleId = $sale->getId(); use PayPal\Api\Amount; use PayPal\Api\Refund; use PayPal\Api\Sale; // ### Refund amount // Includes both the refunded amount (to Payer) // and refunded fee (to Payee). Use the $amt->details // field to mention fees refund details. $amt = new Amount(); $amt->setCurrency('USD')->setTotal(0.01); // ### Refund object $refund = new Refund(); $refund->setAmount($amt); // ###Sale // A sale transaction. // Create a Sale object with the // given sale transaction id. $sale = new Sale(); $sale->setId($saleId); try { // Create a new apiContext object so we send a new // PayPal-Request-Id (idempotency) header for this resource $apiContext = getApiContext($clientId, $clientSecret); // Refund the sale // (See bootstrap.php for more on `ApiContext`) $refundedSale = $sale->refund($refund, $apiContext); } catch (Exception $ex) { // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
function refund_payment($oID, $total = '', $comment = '') { global $order; $orders_query = xtc_db_query("SELECT p.*,\n o.customers_address_format_id\n FROM " . TABLE_PAYPAL_PAYMENT . " p\n JOIN " . TABLE_ORDERS . " o\n ON p.orders_id = o.orders_id\n WHERE p.orders_id = '" . (int) $oID . "'"); if (xtc_db_num_rows($orders_query) > 0) { $orders = xtc_db_fetch_array($orders_query); // auth $apiContext = $this->apiContext(); try { // Get the payment Object by passing paymentId $payment = Payment::get($orders['payment_id'], $apiContext); $valid = true; } catch (Exception $ex) { $this->LoggingManager->log(print_r($ex, true), 'DEBUG'); $valid = false; } if ($valid === true) { // transaction $transactions = $payment->getTransactions(); $transaction = $transactions[0]; $relatedResources = $transaction->getRelatedResources(); for ($i = 0, $n = count($relatedResources); $i < $n; $i++) { $relatedResource = $relatedResources[$i]; if ($relatedResource->__isset('sale')) { $resource = $relatedResource->getSale($relatedResource); break; } if ($relatedResource->__isset('capture')) { $resource = $relatedResource->getCapture($relatedResource); break; } if ($relatedResource->__isset('order')) { continue; } if ($relatedResource->__isset('authorization')) { continue; } if ($relatedResource->__isset('refund')) { continue; } } if (is_object($resource)) { // get amount $amount = $resource->getAmount(); $amount->__unset('details'); if ($total != '' && $total > 0) { $amount->setTotal($total); } // set refund $refund = new Refund(); $refund->setAmount($amount); if ($comment != '') { $refund->setDescription($this->encode_utf8($comment)); } try { $resource->refund($refund, $apiContext); $success = true; } catch (Exception $ex) { $this->LoggingManager->log(print_r($ex, true), 'DEBUG'); if ($ex instanceof \PayPal\Exception\PayPalConnectionException) { $error_json = $ex->getData(); $error = json_decode($error_json, true); $_SESSION['pp_error'] = $error['message']; } } } } } }
public function createRefund($captureId, Amount $amt) { $apiContext = $this->contextFactory->createContext(); $capture = Capture::get($captureId, $apiContext); $refund = new Refund(); $refund->setAmount($amt); $result = $capture->refund($refund, $apiContext); return $result; }
function refundPayment($saleId, $amount, $currency) { $amount = number_format($amount, 2); $apiContext = $this->getApiContext(); $sale = Sale::get($saleId, $apiContext); $refund = new Refund(); if (isset($amount) && strlen($amount) > 0) { $amt = new Amount(); $amt->setCurrency($currency); $amt->setTotal($amount); $refund->setAmount($amt); } $refund = $sale->refund($refund, $apiContext); return $refund; }