function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount) { $this->invoice = $payment->getInvoice(); $params = array('key' => $this->getConfig('key'), 'ref' => $payment->receipt_id, 'uid' => $payment->user_id, 'type' => 1); $params['sign'] = $this->calculateSignature($params, $this->getConfig('secret')); $requst = new Am_HttpRequest(self::URL_TICKET, Am_HttpRequest::METHOD_POST); $requst->addPostParameter($params); $log = $this->logRequest($requst); $responce = $requst->send(); $log->add($responce); if ($responce->getStatus() != 200) { $result->setFailed('Incorrect HTTP response status: ' . $responce->getStatus()); return; } $res = Am_Controller::decodeJson($responce->getBody()); if ($res['result'] == 1) { $trans = new Am_Paysystem_Transaction_Manual($this); $trans->setAmount($amount); $trans->setReceiptId($payment->receipt_id); $result->setSuccess($trans); return; } $result->setFailed($res['errors']); }
public function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount) { $request = new Am_HttpRequest(self::REFUND_URL, Am_HttpRequest::METHOD_POST); $vars = array('MerchantId' => $this->getConfig('merchant_id'), 'TransactionId' => $payment->receipt_id, 'Amount' => $amount, 'ContentType' => 'text'); $vars['SecurityKey'] = $this->getRefundSecurityKey($vars); foreach ($vars as $k => $v) { $request->addPostParameter($k, $v); } $this->logRequest($request); $response = $request->send(); $this->logResponse($response); if ($response->getStatus() != 200) { throw new Am_Exception_InputError("An error occurred during refund request"); } parse_str($response->getBody(), $parsed); if ($parsed['Result'] != 'Ok') { throw new Am_Exception_InputError("An error occurred during refund request: " . $parsed['Message']); } $trans = new Am_Paysystem_Transaction_Manual($this); $trans->setAmount($amount); $trans->setReceiptId($parsed['TransactionId'] . '-refund'); $result->setSuccess($trans); }
public function refundAction() { $this->invoice_payment_id = $this->getInt('invoice_payment_id'); if (!$this->invoice_payment_id) { throw new Am_Exception_InputError("Not payment# submitted"); } $p = $this->getDi()->invoicePaymentTable->load($this->invoice_payment_id); /* @var $p InvoicePayment */ if (!$p) { throw new Am_Exception_InputError("No payment found"); } if ($this->user_id != $p->user_id) { throw new Am_Exception_InputError("Payment belongs to another customer"); } if ($p->isRefunded()) { throw new Am_Exception_InputError("Payment is already refunded"); } $amount = sprintf('%.2f', $this->_request->get('amount')); if ($p->amount < $amount) { throw new Am_Exception_InputError("Refund amount cannot exceed payment amount"); } if ($this->_request->getInt('manual')) { switch ($type = $this->_request->getFiltered('type')) { case 'refund': case 'chargeback': $pl = $this->getDi()->plugins_payment->loadEnabled()->get($p->paysys_id); if (!$pl) { throw new Am_Exception_InputError("Could not load payment plugin [{$pl}]"); } $invoice = $p->getInvoice(); $transaction = new Am_Paysystem_Transaction_Manual($pl); $transaction->setAmount($amount); $transaction->setReceiptId($p->receipt_id . '-manual-' . $type); $transaction->setTime($this->getDi()->dateTime); if ($type == 'refund') { $invoice->addRefund($transaction, $p->receipt_id); } else { $invoice->addChargeback($transaction, $p->receipt_id); } break; case 'correction': $this->getDi()->accessTable->deleteBy(array('invoice_payment_id' => $this->invoice_payment_id)); $invoice = $p->getInvoice(); $p->delete(); $invoice->updateStatus(); break; default: throw new Am_Exception_InputError("Incorrect refund [type] passed:" . $type); } $res = array('success' => true, 'text' => ___("Payment has been successfully refunded")); } else { // automatic /// ok, now we have validated $p here $pl = $this->getDi()->plugins_payment->loadEnabled()->get($p->paysys_id); if (!$pl) { throw new Am_Exception_InputError("Could not load payment plugin [{$pl}]"); } /* @var $pl Am_Paysystem_Abstract */ $result = new Am_Paysystem_Result(); $pl->processRefund($p, $result, $amount); if ($result->isSuccess()) { $p->getInvoice()->addRefund($result->getTransaction(), $p->receipt_id, $amount); $res = array('success' => true, 'text' => ___("Payment has been successfully refunded")); } elseif ($result->isAction()) { $action = $result->getAction(); if ($action instanceof Am_Paysystem_Action_Redirect) { $res = array('success' => 'redirect', 'url' => $result->getUrl()); } else { // todo handle other actions if necessary throw new Am_Exception_NotImplemented("Could not handle refund action " . get_class($action)); } } elseif ($result->isFailure()) { $res = array('success' => false, 'text' => join(";", $result->getErrorMessages())); } } $this->_response->setHeader("Content-type", "application/json"); echo $this->getJson($res); }
function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount) { $request = new Am_HttpRequest("https://" . $this->getConfig('login') . ":" . $this->getConfig('password') . "@payment.architrade.com/cgi-adm/refund.cgi"); $invoice = $payment->getInvoice(); $currency = $this->getCurrencyCode($invoice); $post_params = new stdclass(); $post_params->merchant = $this->getConfig('merchant'); $post_params->amount = $amount * 100; $count = $this->getDi()->db->selectCol("SELECT COUNT(*) FROM ?_invoice_payment\n WHERE invoice_id=?d AND dattm < ?\n ", $payment->invoice_id, $payment->dattm); $post_params->orderId = $invoice->public_id . "-" . sprintf("%03d", array_shift($count)); $post_params->transact = $invoice->data()->get(self::TICKET); $post_params->textreply = 'true'; $post_params->currency = $currency; $post_params->md5key = md5($s2 = $this->getConfig('key2') . md5($s1 = $this->getConfig('key1') . "merchant=" . $this->getConfig('merchant') . "&orderid=" . $invoice->public_id . "&transact=" . $invoice->data()->get(self::TICKET) . "&amount=" . $amount)); $request->addPostParameter((array) $post_params); $response = $request->send(); $response = $this->parseResponse($response->getBody()); if ($response['result'] === 0) { $trans = new Am_Paysystem_Transaction_Manual($this); $trans->setAmount($amount); $trans->setReceiptId($payment->receipt_id . '-dibs-refund'); $result->setSuccess($trans); } else { $result->setFailed(array('Error Processing Refund!')); } }
function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount) { $request = new Am_HttpRequest(self::API_URL, Am_HttpRequest::METHOD_POST); $post_params = new stdclass(); $post_params->protocol = '6'; $post_params->msgtype = 'refund'; $post_params->merchant = $this->getConfig('merchant'); $post_params->amount = intval($amount * 100); $post_params->transaction = $payment->receipt_id; foreach ((array) $post_params as $k => $v) { $cstr .= $v; } $cstr .= $this->getConfig('secret'); $post_params->md5check = md5($cstr); $request->addPostParameter((array) $post_params); $response = $request->send(); $parsedResponse = simplexml_load_string($response->getBody()); if ((string) $parsedResponse->qpstat != '000') { $result->setFailed("Payment failed: Description - " . $this->getErrorMessage((string) $parsedResponse->qpstat) . " QuickPay message - " . $parsedResponse->qpstatmsg); } else { $trans = new Am_Paysystem_Transaction_Manual($this); $trans->setAmount($amount); $trans->setReceiptId($payment->receipt_id . '-quickpay-refund'); $result->setSuccess($trans); } }
function processARUDD($uri) { $request = new Am_HttpRequest($uri, Am_HttpRequest::METHOD_POST); $request->setAuth($this->getConfig('login'), $this->getConfig('passwd')); $response = $request->send(); $origXml = simplexml_load_string($response->getBody()); $xml = simplexml_load_string(base64_decode((string) $origXml->file)); // $log = $this->logRequest($request, 'ARUDD'); // $log->add($response); // $log->add($origXml->asXML()); // $log->add($xml->asXML()); foreach ($xml->Data->ARUDD->Advice->OriginatingAccountRecords->OriginatingAccountRecord->ReturnedDebitItem as $ARUDD) { $ref = (string) $ARUDD['ref']; /* @var $invoice Invoice */ $invoice = $this->getDi()->invoiceTable->findFirstByPublicId(substr($ref, strlen(self::REF_PREFIX))); if ($invoice) { $payments = $invoice->getPaymentRecords(); $p = array_pop($payments); $tr = new Am_Paysystem_Transaction_Manual($this); $tr->setInvoice($invoice); $tr->setReceiptId(sprintf('%s-%s', (string) $ARUDD['transCode'], (string) $ARUDD['returnCode'])); $invoice->addVoid($tr, $p->receipt_id); } } }
function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount) { $result = $this->APIRequest("payment", "credit", array('merchantnumber' => $this->getConfig('id'), 'transactionid' => $payment->receipt_id, 'amount' => $amount * 100)); $xml = $this->getResponseXML($result); if ($xml->creditResponse->creditResult == 'true') { $trans = new Am_Paysystem_Transaction_Manual($this); $trans->setAmount($amount); $trans->setReceiptId($payment->receipt_id . '-epay-refund'); $result->setSuccess($trans); } else { $result->setFailed(array('Error Processing Refund!')); } }
function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount) { list(, $trans_id) = split("-", $payment->receipt_id); try { $r = new Am_HttpRequest($this->getAPIURL(self::API_REFUND, array('TRANSACTION_ID' => $trans_id, 'MERCHANT_ID' => $this->getConfig("merchant_id"), 'ZombaioGWPass' => $this->getConfig("password"), 'Refund_Type' => 1))); $response = $r->send(); } catch (Exception $e) { $this->getDi()->errorLogTable->logException($e); } if ($response && $response->getBody() == 1) { $trans = new Am_Paysystem_Transaction_Manual($this); $trans->setAmount($amount); $trans->setReceiptId($payment->receipt_id . '-zombaio-refund'); $result->setSuccess($trans); } else { $result->setFailed(array('Error Processing Refund!')); } }
public function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount) { $request = $this->createHttpRequest(); $ps = new stdclass(); $ps->type = 'rfnd'; $ps->reason = 'ticket.type.refund.8'; $ps->comment = 'refund request for aMember user (' . $payment->getUser()->login . ')'; if (doubleval($amount) == doubleval($payment->amount)) { $ps->refundType = 'FULL'; } else { $ps->refundType = 'PARTIAL_AMOUNT'; $ps->refundAmount = $amount; } $get_params = http_build_query((array) $ps, '', '&'); $request->setUrl($s = 'https://api.clickbank.com/rest/1.3/tickets/' . $payment->receipt_id . "?{$get_params}"); $request->setHeader(array('Content-Length' => '0', 'Accept' => 'application/xml', 'Authorization' => $this->getConfig('dev_key') . ':' . $this->getConfig('clerk_key'))); $request->setMethod(Am_HttpRequest::METHOD_POST); $this->logRequest($request); $request->setMethod('POST'); $response = $request->send(); $this->logResponse($response); if ($response->getStatus() != 200 && $response->getBody() != 'Refund ticket already open') { throw new Am_Exception_InputError("An error occurred during refund request"); } $trans = new Am_Paysystem_Transaction_Manual($this); $trans->setAmount($amount); $trans->setReceiptId($payment->receipt_id . '-clickbank-refund'); $result->setSuccess($trans); }
public function handleRecord($id, $record) { switch ($this->_vars['action']) { case 'access': switch ($this->_vars['access_type']) { case 'exact': $begin_date = $this->_vars['begine_date']; $expire_date = $this->_vars['expire_date']; break; case 'period': $invoice = $this->grid->getDi()->invoiceRecord; $invoice->setUser($this->grid->getDi()->userTable->load($id)); $product = $this->grid->getDi()->productTable->load($this->_vars['product_id']); $begin_date = $product->calculateStartDate($this->grid->getDi()->sqlDate, $invoice); $p = new Am_Period($this->_vars['period']); $expire_date = $p->addTo($begin_date); break; } $a = $this->grid->getDi()->accessRecord; $a->begin_date = $begin_date; $a->expire_date = $expire_date; $a->product_id = $this->_vars['product_id']; $a->user_id = $id; $a->comment = $this->_vars['comment']; $a->insert(); break; case 'payment': $invoice = $this->grid->getDi()->invoiceRecord; $invoice->user_id = $id; $invoice->add($this->grid->getDi()->productTable->load($this->_vars['product_id'])); $items = $invoice->getItems(); $item = $items[0]; $item->first_price = $item->first_total = $this->_vars['amount']; $item->second_price = $item->second_total = 0; $item->rebill_times = 0; $item->second_period = null; $invoice->first_subtotal = $invoice->first_total = $this->_vars['amount']; $invoice->second_subtotal = $invoice->second_total = 0; $invoice->rebill_times = 0; $invoice->second_period = null; $invoice->first_period = $item->first_period; $invoice->paysys_id = $this->_vars['paysys_id']; $invoice->comment = $this->_vars['comment'] ? $this->_vars['comment'] : 'mass-subscribe'; $invoice->save(); $tr = new Am_Paysystem_Transaction_Manual($this->grid->getDi()->plugins_payment->loadGet($invoice->paysys_id)); $tr->setAmount($this->_vars['amount']); $tr->setTime(new DateTime($this->_vars['dattm'])); $tr->setReceiptId('mass-subscribe-' . uniqid() . '-' . $invoice->pk()); $invoice->addPayment($tr); break; } }
public function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount) { // Request to check state of payment ; must be confirmed / paid_out $response = $this->_sendRequest('/payments/' . $payment->transaction_id, null, 'GET'); if ($response->getStatus() !== 200) { $result->setFailed('An error occured, unable to find the payment.'); return $result; } $response = json_decode($response->getBody(), true); if (!in_array($response['payments']['status'], array('confirmed', 'paid_out'))) { $result->setFailed('Payment status must be either "Confirmed" or "Paid out" at GoCardLess. Current state is "' . $response['payments']['status'] . '"'); return $result; } $response = $this->_sendRequest('/refunds/', array('refunds' => array('amount' => intval(doubleval($amount) * 100), 'total_amount_confirmation' => intval(doubleval($amount) * 100), 'links' => array('payment' => $payment->transaction_id)))); if ($response->getStatus() !== 201) { throw new Am_Exception_InputError("An error occurred while cancellation request"); } $trans = new Am_Paysystem_Transaction_Manual($this); $trans->setAmount($amount); $trans->setReceiptId($payment->receipt_id . '-gocardlesspro-refund'); $result->setSuccess($trans); }
function processRefund__(InvoicePayment $payment, Am_Paysystem_Result $result, $amount) { list(, $trans_id) = split("-", $payment->receipt_id); try { $r = new Am_HttpRequest('http://srs.segpay.com/ADM.asmx/CancelMembership' . '?Userid=' . $this->getConfig('userid') . '&UserAccessKey=' . $this->getCOnfig('useraccesskey') . '&PurchaseID=' . $trans_id . '&CancelReason='); $response = $r->send(); } catch (Exception $e) { $this->getDi()->errorLogTable->logException($e); } if ($response && $response->getBody() == '<string>Successful</string>') { $trans = new Am_Paysystem_Transaction_Manual($this); $trans->setAmount($amount); $trans->setReceiptId($payment->receipt_id); $result->setSuccess($trans); } else { $result->setFailed(array('Error Processing Refund! ' . $response->getBody())); } }
public function handleRecord($id, $record) { if (!$this->_vars['add_payment']) { $a = $this->grid->getDi()->accessRecord; $a->begin_date = $this->_vars['start_date']; $a->expire_date = $this->_vars['expire_date']; $a->product_id = $this->_vars['product_id']; $a->user_id = $id; $a->insert(); } else { $invoice = $this->grid->getDi()->invoiceRecord; $invoice->user_id = $id; $invoice->add($this->_getProduct($this->_vars['product_id'])); $invoice->paysys_id = 'free'; $invoice->comment = 'mass-subscribe'; $invoice->calculate(); $invoice->save(); $tr = new Am_Paysystem_Transaction_Manual($this->grid->getDi()->plugins_payment->loadGet('free')); $tr->setAmount($this->_vars['amount']); $tr->setTime(new DateTime($this->_vars['start_date'])); $tr->setReceiptId('mass-subscribe-' . uniqid()); $invoice->addPayment($tr); } }
function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount) { $log = Am_Di::getInstance()->invoiceLogRecord; $log->title = "refundTransaction"; $log->paysys_id = $this->getId(); $apireq = new Am_Paysystem_PaypalApiRequest($this); $apireq->refundTransaction($payment); $res = $apireq->sendRequest($log); $log->setInvoice($payment->getInvoice()); $log->update(); if ($res['ACK'] != 'Success') { throw new Am_Exception_InputError('Transaction was not refunded. Got error from paypal: ' . $res['L_SHORTMESSAGE0']); } $trans = new Am_Paysystem_Transaction_Manual($this); $trans->setAmount($amount); $trans->setReceiptId($res['REFUNDTRANSACTIONID']); $result->setSuccess(); }
public function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount) { if (!$this->getApi()) { throw new Am_Exception_Paysystem_NotConfigured("No 2Checkout API username/password configured - could not do refund"); } $log = $this->getDi()->invoiceLogRecord; $log->setInvoice($payment->getInvoice()); $return = $this->getApi()->refundInvoice($payment->receipt_id, 5, "Customer Request"); $log->add($return); if ($return['response_code'] == 'OK') { $trans = new Am_Paysystem_Transaction_Manual($this); $trans->setAmount($amount); $trans->setReceiptId($payment->receipt_id . '-2co-refund'); $result->setSuccess($trans); } else { $result->setFailed($return['response_message']); } }