Example #1
0
 /**
  * Creates an Simplify_Refund object
  * @param     array $hash a map of parameters; valid keys are:<dl style="padding-left:10px;">
  *     <dt><tt>amount</tt></dt>    <dd>Amount of the refund in minor units. Example: 1000 = 10.00 <strong>required </strong></dd>
  *     <dt><tt>payment</tt></dt>    <dd>ID of the payment for the refund <strong>required </strong></dd>
  *     <dt><tt>reason</tt></dt>    <dd>Reason for the refund </dd></dl>
  * @param     string publicKey Public key. If null, the value of static Simplify::$publicKey will be used
  * @param     string privateKey Private key. If null, the value of static Simplify::$privateKey will be used
  * @return    Refund a Refund object.
  */
 public static function createRefund($hash, $publicKey = null, $privateKey = null)
 {
     $instance = new Simplify_Refund();
     $instance->setAll($hash);
     $object = Simplify_PaymentsApi::createObject($instance, $publicKey, $privateKey);
     return $object;
 }
Example #2
0
 /**
  * Creates an Simplify_Refund object
  * @param     array $hash a map of parameters; valid keys are:<dl style="padding-left:10px;">
  *     <dt><tt>amount</tt></dt>    <dd>Amount of the refund in the smallest unit of your currency. Example: 100 = $1.00USD [min value: 1] <strong>required </strong></dd>
  *     <dt><tt>payment</tt></dt>    <dd>ID of the payment for the refund <strong>required </strong></dd>
  *     <dt><tt>reason</tt></dt>    <dd>Reason for the refund </dd>
  *     <dt><tt>reference</tt></dt>    <dd>Custom reference field to be used with outside systems. </dd>
  *     <dt><tt>replayId</tt></dt>    <dd>An identifier that can be sent to uniquely identify a refund request to facilitate retries due to I/O related issues. This identifier must be unique for your account (sandbox or live) across all of your refunds. If supplied, we will check for a refund on your account that matches this identifier. If found we will return an identical response to that of the original request. [max length: 50, min length: 1] </dd>
  *     <dt><tt>statementDescription.name</tt></dt>    <dd>Merchant name. <strong>required </strong></dd>
  *     <dt><tt>statementDescription.phoneNumber</tt></dt>    <dd>Merchant contact phone number. </dd></dl>
  * @param     $authentication -  information used for the API call.  If no value is passed the global keys Simplify::public_key and Simplify::private_key are used.  <i>For backwards compatibility the public and private keys may be passed instead of the authentication object.<i/>
  * @return    Refund a Refund object.
  */
 public static function createRefund($hash, $authentication = null)
 {
     $args = func_get_args();
     $authentication = Simplify_PaymentsApi::buildAuthenticationObject($authentication, $args, 2);
     $instance = new Simplify_Refund();
     $instance->setAll($hash);
     $object = Simplify_PaymentsApi::createObject($instance, $authentication);
     return $object;
 }
 /**
  * Process refunds.
  * WooCommerce 2.2 or later.
  *
  * @param  int $order_id
  * @param  float $amount
  * @param  string $reason
  * @uses   Simplify_ApiException
  * @uses   Simplify_BadRequestException
  * @return bool|WP_Error
  */
 public function process_refund($order_id, $amount = null, $reason = '')
 {
     try {
         $payment_id = get_post_meta($order_id, '_transaction_id', true);
         $refund = Simplify_Refund::createRefund(array('amount' => $amount * 100, 'payment' => $payment_id, 'reason' => $reason, 'reference' => $order_id));
         if ('APPROVED' == $refund->paymentStatus) {
             return true;
         } else {
             throw new Simplify_ApiException(__('Refund was declined.', 'woocommerce'));
         }
     } catch (Simplify_ApiException $e) {
         if ($e instanceof Simplify_BadRequestException && $e->hasFieldErrors() && $e->getFieldErrors()) {
             foreach ($e->getFieldErrors() as $error) {
                 return new WP_Error('simplify_refund_error', $error->getFieldName() . ': "' . $error->getMessage() . '" (' . $error->getErrorCode() . ')');
             }
         } else {
             return new WP_Error('simplify_refund_error', $e->getMessage());
         }
     }
     return false;
 }