A refund transaction.
Inheritance: extends PayPal\Common\PayPalResourceModel
Exemplo n.º 1
1
 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;
 }
Exemplo n.º 2
0
 /**
  * @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());
     }
 }
Exemplo n.º 3
0
 public function testSerializeDeserialize()
 {
     $r1 = $this->refund;
     $r2 = new Refund();
     $r2->fromJson($r1->toJson());
     $this->assertEquals($r1, $r2);
 }
Exemplo n.º 4
0
 /**
  * @dataProvider mockProvider
  * @param Refund $obj
  */
 public function testGet($obj, $mockApiContext)
 {
     $mockPPRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
     $mockPPRestCall->expects($this->any())->method('execute')->will($this->returnValue(RefundTest::getJson()));
     $result = $obj->get("refundId", $mockApiContext, $mockPPRestCall);
     $this->assertNotNull($result);
 }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
 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());
 }
Exemplo n.º 7
0
 public static function get($refundId, $apiContext = null)
 {
     if ($refundId == null || strlen($refundId) <= 0) {
         throw new \InvalidArgumentException("refundId cannot be null or empty");
     }
     $payLoad = "";
     if ($apiContext == null) {
         $apiContext = new ApiContext(self::$credential);
     }
     $call = new PPRestCall($apiContext);
     $json = $call->execute(array('PayPal\\Rest\\RestHandler'), "/v1/payments/refund/{$refundId}", "GET", $payLoad);
     $ret = new Refund();
     $ret->fromJson($json);
     return $ret;
 }
 function get_transaction($id)
 {
     // auth
     $apiContext = $this->apiContext();
     try {
         $payment = Sale::get($id, $apiContext);
         $valid = true;
     } catch (Exception $ex) {
         $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
         $valid = false;
     }
     if ($valid === true) {
         return $payment;
     }
     try {
         $payment = Authorization::get($id, $apiContext);
         $valid = true;
     } catch (Exception $ex) {
         $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
         $valid = false;
     }
     if ($valid === true) {
         return $payment;
     }
     try {
         $payment = Capture::get($id, $apiContext);
         $valid = true;
     } catch (Exception $ex) {
         $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
         $valid = false;
     }
     if ($valid === true) {
         return $payment;
     }
     try {
         $payment = Refund::get($id, $apiContext);
         $valid = true;
     } catch (Exception $ex) {
         $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
         $valid = false;
     }
     if ($valid === true) {
         return $payment;
     }
 }
Exemplo n.º 9
0
 /**
  * Creates (and processes) a new Refund Transaction added as a related resource.
  *
  * @param Refund $refund
  * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
  * @return Refund
  */
 public function refund($refund, $apiContext = null)
 {
     ArgumentValidator::validate($this->getId(), "Id");
     ArgumentValidator::validate($refund, 'refund');
     $payLoad = $refund->toJSON();
     if ($apiContext == null) {
         $apiContext = new ApiContext(self::$credential);
     }
     $call = new PayPalRestCall($apiContext);
     $json = $call->execute(array('PayPal\\Handler\\RestHandler'), "/v1/payments/capture/{$this->getId()}/refund", "POST", $payLoad);
     $ret = new Refund();
     $ret->fromJson($json);
     return $ret;
 }
Exemplo n.º 10
0
 /**
  * Refund a captured payment by passing the capture_id in the request URI. In addition, include an amount object in the body of the request JSON.
  *
  * @param Refund $refund
  * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
  * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls
  * @return Refund
  */
 public function refund($refund, $apiContext = null, $restCall = null)
 {
     ArgumentValidator::validate($this->getId(), "Id");
     ArgumentValidator::validate($refund, 'refund');
     $payLoad = $refund->toJSON();
     $json = self::executeCall("/v1/payments/capture/{$this->getId()}/refund", "POST", $payLoad, null, $apiContext, $restCall);
     $ret = new Refund();
     $ret->fromJson($json);
     return $ret;
 }
Exemplo n.º 11
0
 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'];
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 12
0
 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;
 }
Exemplo n.º 13
0
 /**
  * @path /v1/payments/refund/:refund-id
  * @method GET
  * @param string $refundid	  	 
  */
 public static function get($refundid)
 {
     if ($refundid == null || strlen($refundid) <= 0) {
         throw new \InvalidArgumentException("refundid cannot be null or empty");
     }
     $payLoad = "";
     $apiContext = new ApiContext(self::$credential);
     $call = new Call();
     $json = $call->execute("/v1/payments/refund/{$refundid}", "GET", $payLoad, $apiContext);
     $ret = new Refund();
     $ret->fromJson($json);
     return $ret;
 }
Exemplo n.º 14
0
 /**
  * @path /v1/payments/sale/:sale-id/refund
  * @method POST
  * @param Refund $refund	  
  * @param PayPal\Rest\ApiContext $apiContext optional	  	 
  */
 public function refund($refund, $apiContext = null)
 {
     if ($refund == null) {
         throw new \InvalidArgumentException("refund cannot be null");
     }
     if ($this->getId() == null) {
         throw new \InvalidArgumentException("Id cannot be null");
     }
     $payLoad = $refund->toJSON();
     if ($apiContext == null) {
         $apiContext = new ApiContext(self::$credential);
     }
     $call = new Call();
     $json = $call->execute("/v1/payments/sale/{$this->getId()}/refund", "POST", $payLoad, $apiContext);
     $this->fromJson($json);
     return $this;
 }
 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;
 }
Exemplo n.º 16
0
 /**
  * Retrieve details about a specific refund by passing the refund_id in the request URI.
  *
  * @param string         $refundId
  * @param ApiContext     $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
  * @param PayPalRestCall $restCall   is the Rest Call Service that is used to make rest calls
  * @return Refund
  */
 public static function get($refundId, $apiContext = null, $restCall = null)
 {
     ArgumentValidator::validate($refundId, 'refundId');
     $payLoad = "";
     $json = self::executeCall("/v1/payments/refund/{$refundId}", "GET", $payLoad, null, $apiContext, $restCall);
     $ret = new Refund();
     $ret->fromJson($json);
     return $ret;
 }
Exemplo n.º 17
0
// using the Payments API.
// 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) {
Exemplo n.º 18
0
<?php

// # Refund Capture Sample
// This sample code demonstrates how you can
// process a refund on a Captured transaction.
// API used: /v1/payments/capture/{<captureID>}/refund
/** @var Capture $capture */
$capture = (require 'AuthorizationCapture.php');
use PayPal\Api\Capture;
use PayPal\Api\Refund;
// ### Refund
// Create a refund object indicating
// refund amount and call the refund method
$refund = new Refund();
$refund->setAmount($amt);
try {
    // Create a new apiContext object so we send a new
    // PayPal-Request-Id (idempotency) header for this resource
    $apiContext = getApiContext($clientId, $clientSecret);
    $captureRefund = $capture->refund($refund, $apiContext);
} catch (Exception $ex) {
    // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
    ResultPrinter::printError("Refund Capture", "Capture", null, $refund, $ex);
    exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Refund Capture", "Capture", $captureRefund->getId(), $refund, $captureRefund);
Exemplo n.º 19
0
 /**
  * Refund
  *
  * @param \Paypal\Api\Refund           $refund
  * @param \PayPal\Rest\ApiContext|null $apiContext
  *
  * @return Refund
  * @throws \InvalidArgumentException
  */
 public function refund($refund, $apiContext = null)
 {
     if ($this->getId() == null) {
         throw new \InvalidArgumentException("Id cannot be null");
     }
     if ($refund == null) {
         throw new \InvalidArgumentException("refund cannot be null or empty");
     }
     $payLoad = $refund->toJSON();
     if ($apiContext == null) {
         $apiContext = new ApiContext(self::$credential);
     }
     $call = new PPRestCall($apiContext);
     $json = $call->execute(array('PayPal\\Rest\\RestHandler'), "/v1/payments/sale/{$this->getId()}/refund", "POST", $payLoad);
     $ret = new Refund();
     $ret->fromJson($json);
     return $ret;
 }
Exemplo n.º 20
0
 /**
  * Obtain the Refund transaction resource for the given identifier.
  *
  * @param string $refundId
  * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
  * @return Refund
  */
 public static function get($refundId, $apiContext = null)
 {
     ArgumentValidator::validate($refundId, 'refundId');
     $payLoad = "";
     if ($apiContext == null) {
         $apiContext = new ApiContext(self::$credential);
     }
     $call = new PayPalRestCall($apiContext);
     $json = $call->execute(array('PayPal\\Handler\\RestHandler'), "/v1/payments/refund/{$refundId}", "GET", $payLoad);
     $ret = new Refund();
     $ret->fromJson($json);
     return $ret;
 }