Exemplo n.º 1
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $req = new Am_HttpRequest(sprintf('https://gateway-japa.americanexpress.com/api/rest/version/23/merchant/%s/session', $this->getConfig('merchant')), Am_HttpRequest::METHOD_POST);
     $req->setAuth('merchant.' . $this->getConfig('merchant'), $this->getConfig('password'));
     $req->setBody(Am_Controller::getJson(array('apiOperation' => 'CREATE_PAYMENT_PAGE_SESSION', 'order' => array('id' => $invoice->public_id, 'amount' => $invoice->first_total, 'currency' => $invoice->currency), 'paymentPage' => array('cancelUrl' => $this->getCancelUrl(), 'returnUrl' => $this->getPluginUrl('thanks')))));
     $this->logRequest($req);
     $res = $req->send();
     $this->logResponse($res);
     if ($res->getStatus() != 201) {
         $result->setFailed(sprintf('Incorrect Responce Status From Paysystem [%s]', $res->getStatus()));
         return;
     }
     $msg = Am_Controller::decodeJson($res->getBody());
     if ($msg['result'] == 'ERROR') {
         $result->setFailed($msg['error']['explanation']);
         return;
     }
     $invoice->data()->set(self::DATA_KEY, $msg['successIndicator'])->update();
     $a = new Am_Paysystem_Action_Redirect(self::URL);
     $a->{'merchant'} = $this->getConfig('merchant');
     $a->{'order.description'} = $invoice->getLineDescription();
     $a->{'paymentPage.merchant.name'} = $this->getDi()->config->get('site_title');
     $a->{'session.id'} = $msg['session']['id'];
     $this->logRequest($a);
     $result->setAction($a);
 }
Exemplo n.º 2
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $req = $this->createHttpRequest();
     $req->setUrl(self::POST_URL);
     $req->addPostParameter('Key', $this->getConfig('app_key'));
     $req->addPostParameter('Secret', $this->getConfig('app_secret'));
     $req->addPostParameter('DestinationId', $this->getConfig('destination_id'));
     $req->addPostParameter('OrderId', $invoice->public_id);
     $req->addPostParameter('Amount', $invoice->first_total);
     $req->addPostParameter('Test', $this->getConfig('testing') ? 'true' : 'false');
     $req->addPostParameter('Redirect', $this->getPluginUrl('thanks') . '?id=' . $invoice->getSecureId('THANKS'));
     $req->addPostParameter('Name', $this->getDi()->config->get('site_title'));
     $req->addPostParameter('Description', $invoice->getLineDescription());
     $req->addPostParameter('Callback', $this->getPluginUrl('ipn'));
     $this->logRequest($req);
     $req->setMethod(Am_HttpRequest::METHOD_POST);
     $response = $req->send();
     $this->logResponse($response);
     $resp = $response->getBody();
     if (strstr($resp, "Invalid+application+credentials")) {
         $result->setFailed("Invalid Application Credentials.");
         return;
     } elseif (strstr($resp, "error")) {
         $result->setFailed("Invalid Response From Dwolla's server.");
         return;
     }
     $i = strpos($resp, "checkout/");
     $checkout_id = substr($resp, $i + 9, 36);
     $a = new Am_Paysystem_Action_Redirect(self::REDIRECT_URL . $checkout_id);
     $result->setAction($a);
 }
Exemplo n.º 3
0
 public function run(Am_Paysystem_Result $result)
 {
     $this->result = $result;
     $log = $this->getInvoiceLog();
     $log->add($this->request);
     $this->response = $this->request->send();
     $log->add($this->response);
     $this->validateResponseStatus($this->result);
     if ($this->result->isFailure()) {
         return;
     }
     try {
         $this->parseResponse();
         // validate function must set success status
         $this->validate();
         if ($this->result->isSuccess()) {
             $this->processValidated();
         }
     } catch (Exception $e) {
         if ($e instanceof PHPUnit_Framework_Error) {
             throw $e;
         }
         if ($e instanceof PHPUnit_Framework_Asser) {
             throw $e;
         }
         if (!$result->isFailure()) {
             $result->setFailed(___("Payment failed"));
         }
         $log->add($e);
     }
 }
Exemplo n.º 4
0
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     if ($this->getConfig('set_failed')) {
         $result->setFailed('Transaction declined.');
     } elseif ($cc->cc_number != '4111111111111111') {
         $result->setFailed("Please use CC# 4111-1111-1111-1111 for successful payments with demo plugin");
     } elseif ($doFirst && doubleval($invoice->first_total) <= 0) {
         // free trial
         $tr = new Am_Paysystem_Transaction_Free($this);
         $tr->setInvoice($invoice);
         $tr->process();
         $result->setSuccess($tr);
     } else {
         $tr = new Am_Paysystem_Transaction_CcDemo($this, $invoice, null, $doFirst);
         $result->setSuccess($tr);
         $tr->processValidated();
     }
 }
Exemplo n.º 5
0
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     if ($cc->cc_number != '4111111111111111') {
         $result->setFailed("Please use CC# 4111-1111-1111-1111 for successful payments with demo plugin");
     } else {
         $tr = new Am_Paysystem_Transaction_CcDemo($this, $invoice, null, $doFirst);
         $result->setSuccess($tr);
         $tr->processValidated();
     }
 }
Exemplo n.º 6
0
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     $client = new SoapClient(self::WSDL);
     $user = $invoice->getUser();
     if ($cc) {
         $data = array('customer_firstname' => $user->name_f ? $user->name_f : $cc->cc_name_f, 'customer_lastname' => $user->name_l ? $user->name_l : $cc->cc_name_l, 'customer_email' => $user->email, 'holder_firstname' => $cc->cc_name_f, 'holder_lastname' => $cc->cc_name_l, 'pan' => $cc->cc_number, 'digit' => $cc->getCvv(), 'exp' => $cc->getExpire('%02d-20%02d'));
         $data = base64_encode(serialize($data));
         $param = array($this->getConfig('apiKey'), $data);
         $request = new SoapRequestWrapperComenpay($client, 'AddCustomerData', $param);
         $t = new Am_Paysystem_Transaction_CreditCard_Comenpay_AddCustomerData($this, $invoice, $request, $user);
         $r = new Am_Paysystem_Result();
         $t->run($r);
         if ($r->isFailure()) {
             $result->setFailed($r->getErrorMessages());
             return;
         }
     }
     if (!$user->data()->get(self::COMENPAY_CARD_TOKEN)) {
         $result->setFailed('Can not process payment: customer has not associated CC');
         return;
     }
     if ($doFirst && !(double) $invoice->first_total) {
         //free trial
         $t = new Am_Paysystem_Transaction_Free($this);
         $t->setInvoice($invoice);
         $t->process();
         $result->setSuccess();
     } else {
         $payment = null;
         @(list($payment) = $invoice->getPaymentRecords());
         $data = array('paccount_id' => $this->getConfig('paccount_id'), 'type' => $payment ? 'REBILL' : 'BILL', 'transaction_ip' => $user->last_ip, 'amount_cnts' => 100 * ($doFirst ? $invoice->first_total : $invoice->second_total), 'client_reference' => $invoice->public_id, 'client_customer_id' => $user->pk(), 'affiliate_id' => 0, 'site_url' => $this->getDi()->config->get('site_url'), 'member_login' => $user->login, 'support_url' => $this->getDi()->config->get('site_url'), 'support_tel' => 'N/A', 'support_email' => $this->getDi()->config->get('admin_email'), 'customer_lang' => 'en', 'customer_useragent' => $user->last_user_agent, 'billing_invoicing_id' => 0, 'billing_description' => $invoice->getLineDescription(), 'billing_preauth_duration' => 0, 'billing_rebill_period' => 0, 'billing_rebill_duration' => 0, 'billing_rebill_price_cnts' => 100 * $invoice->second_total);
         if ($payment) {
             $data['billing_initial_transaction_id'] = $payment->receipt_id;
         }
         $param = array($this->getConfig('apiKey'), $user->data()->get(self::COMENPAY_CARD_TOKEN), $user->data()->get(self::COMENPAY_CARD_KEY), $data);
         $request = new SoapRequestWrapperComenpay($client, 'Transaction', $param);
         $t = new Am_Paysystem_Transaction_CreditCard_Comenpay_Transaction($this, $invoice, $request, $doFirst);
         $t->run($result);
     }
 }
Exemplo n.º 7
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $user = $invoice->getUser();
     $req = new Am_HttpRequest($this->host() . 'trnRegister', Am_HttpRequest::METHOD_POST);
     $vars = array('p24_merchant_id' => $this->getConfig('merchant_id'), 'p24_pos_id' => $this->getConfig('pos_id'), 'p24_session_id' => $invoice->public_id, 'p24_amount' => $invoice->first_total * 100, 'p24_currency' => $invoice->currency, 'p24_description' => $invoice->getLineDescription(), 'p24_email' => $user->email, 'p24_country' => $user->country, 'p24_url_return' => $this->getReturnUrl(), 'p24_url_status' => $this->getPluginUrl('ipn'), 'p24_time_limit' => 5, 'p24_encoding' => 'UTF-8', 'p24_api_version' => '3.2');
     $vars['p24_sign'] = $this->sign(array($vars['p24_session_id'], $vars['p24_pos_id'], $vars['p24_amount'], $vars['p24_currency']));
     $req->addPostParameter($vars);
     $this->logRequest($req);
     $resp = $req->send();
     $this->logResponse($resp);
     if ($resp->getStatus() != 200) {
         $result->setFailed('Incorrect HTTP response status: ' . $resp->getStatus());
         return;
     }
     parse_str($resp->getBody(), $params);
     if ($params['error']) {
         $result->setFailed(explode('&', $params['errorMessage']));
         return;
     }
     $a = new Am_Paysystem_Action_Redirect($this->host() . 'trnRequest/' . $params['token']);
     $result->setAction($a);
 }
Exemplo n.º 8
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $user = $invoice->getUser();
     if (!$user->data()->get(self::DATA_KEY)) {
         //create user
         $req = new Am_HttpRequest($this->url(), Am_HttpRequest::METHOD_POST);
         $req->addPostParameter(array('fn' => 'eWallet_RegisterUser', 'MerchantGUID' => $this->getConfig('MerchantGUID'), 'MerchantPassword' => $this->getConfig('MerchantPassword'), 'UserName' => $user->login, 'FirstName' => $user->name_f, 'LastName' => $user->name_l, 'EmailAddress' => $user->email, 'DateOfBirth' => '1/1/1900'));
         $this->logRequest($req);
         $resp = $req->send();
         $this->logResponse($resp);
         if ($resp->getStatus() != 200) {
             $result->setFailed('Incorrect HTTP response status: ' . $resp->getStatus());
             return;
         }
         parse_str($resp->getBody(), $tmp);
         parse_str($tmp['response'], $params);
         if ($params['m_Code'] != 'NO_ERROR') {
             $result->setFailed($params['m_Text']);
             return;
         }
         $user->data()->set(self::DATA_KEY, $params['TransactionRefID'])->update();
     }
     //create invoice
     $req = new Am_HttpRequest($this->url(), Am_HttpRequest::METHOD_POST);
     $arrItems = array('Amount' => $invoice->first_total, 'CurrencyCode' => $invoice->currency, 'ItemDescription' => $invoice->getLineDescription(), 'MerchantReferenceID' => $invoice->public_id, 'UserReturnURL' => $this->getReturnUrl(), 'MustComplete' => 'false', 'IsSubscription' => 'false');
     $req->addPostParameter(array('fn' => 'eWallet_AddCheckoutItems', 'MerchantGUID' => $this->getConfig('MerchantGUID'), 'MerchantPassword' => $this->getConfig('MerchantPassword'), 'UserName' => $user->login, 'arrItems' => sprintf('[%s]', http_build_query($arrItems)), 'AutoChargeAccount' => 'false'));
     $this->logRequest($req);
     $resp = $req->send();
     $this->logResponse($resp);
     if ($resp->getStatus() != 200) {
         $result->setFailed('Incorrect HTTP response status: ' . $resp->getStatus());
         return;
     }
     parse_str($resp->getBody(), $tmp);
     parse_str($tmp['response'], $params);
     if ($params['m_Code'] != 'NO_ERROR') {
         $result->setFailed($params['m_Text']);
         return;
     }
     //login and redirect
     $req = new Am_HttpRequest($this->url(), Am_HttpRequest::METHOD_POST);
     $req->addPostParameter(array('fn' => 'eWallet_RequestUserAutoLogin', 'MerchantGUID' => $this->getConfig('MerchantGUID'), 'MerchantPassword' => $this->getConfig('MerchantPassword'), 'UserName' => $user->login));
     $this->logRequest($req);
     $resp = $req->send();
     $this->logResponse($resp);
     if ($resp->getStatus() != 200) {
         $result->setFailed('Incorrect HTTP response status: ' . $resp->getStatus());
         return;
     }
     parse_str($resp->getBody(), $tmp);
     parse_str($tmp['responset'], $params);
     if ($params['m_Code'] != 'NO_ERROR') {
         $result->setFailed($params['m_Text']);
         return;
     }
     $a = new Am_Paysystem_Action_Redirect($this->urlLogin());
     $a->secKey = $params['m_ProcessorTransactionRefNumber'];
     $result->setAction($a);
 }
Exemplo n.º 9
0
 public function _doBill(Invoice $invoice, $doFirst, CcRecord $cc, Am_Paysystem_Result $result)
 {
     $addCc = true;
     // if it is a first charge, or user have valid CC info in file, we should use cc_info instead of reference transaction.
     // This is necessary when data was imported from amember v3 for example
     if ($doFirst || !empty($cc->cc_number) && $cc->cc_number != '0000000000000000') {
         if ($doFirst && doubleval($invoice->first_total) == 0) {
             $tr = new Am_Paysystem_Payflow_Transaction_Authorization($this, $invoice, $doFirst, $cc);
         } else {
             $tr = new Am_Paysystem_Payflow_Transaction_Sale($this, $invoice, $doFirst, $cc);
         }
     } else {
         $user = $invoice->getUser();
         $profileId = $user->data()->get(self::USER_PROFILE_KEY);
         if (!$profileId) {
             return $result->setFailed(array("No saved reference transaction for customer"));
         }
         $tr = new Am_Paysystem_Payflow_Transaction_Sale($this, $invoice, $doFirst, null, $profileId);
     }
     $tr->run($result);
 }
Exemplo n.º 10
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $u = $invoice->getUser();
     $msp = $this->createMSP();
     $msp->merchant['notification_url'] = $this->getPluginUrl('ipn');
     $msp->merchant['cancel_url'] = $this->getCancelUrl();
     $msp->merchant['redirect_url'] = $this->getReturnUrl();
     $msp->customer['locale'] = 'en';
     $msp->customer['firstname'] = $u->name_f;
     $msp->customer['lastname'] = $u->name_l;
     $msp->customer['zipcode'] = $u->zip;
     $msp->customer['city'] = $u->city;
     $msp->customer['country'] = $u->country;
     $msp->customer['email'] = $u->email;
     $msp->parseCustomerAddress($member['street']);
     /*
      * Transaction Details
      */
     $msp->transaction['id'] = $invoice->public_id;
     // generally the shop's order ID is used here
     $msp->transaction['currency'] = $invoice->currency;
     $msp->transaction['amount'] = $invoice->first_total * 100;
     // cents
     $msp->transaction['description'] = $invoice->getLineDescription();
     $out = '';
     foreach ($invoice->getItems() as $item) {
         $out .= sprintf('<li>%s</li>', htmlspecialchars($item->item_title));
     }
     $msp->transaction['items'] = sprintf('<br/><ul>%s</ul>', $out);
     $url = $msp->startTransaction();
     if ($msp->error) {
         $result->setFailed(___('Error happened during payment process. ') . ' (' . $msp->error_code . ": " . $msp->error . ')');
         return;
     }
     $a = new Am_Paysystem_Action_Redirect($url);
     $result->setAction($a);
 }
Exemplo n.º 11
0
 public function storeCreditCard(CcRecord $cc, Am_Paysystem_Result $result)
 {
     $profiles = array();
     //Find all profiles which should be updated.
     foreach ($this->getDi()->db->selectPage($total, "\n            SELECT d.value, i.invoice_id \n            FROM ?_data d LEFT JOIN ?_invoice i \n            ON d.`table` = 'invoice' AND d.`key` = ? AND  d.id = i.invoice_id \n            WHERE i.user_id = ? AND i.status = ?", self::PAYPAL_PROFILE_ID, $cc->user_id, Invoice::RECURRING_ACTIVE) as $profile) {
         $profiles[$profile['value']] = $profile['invoice_id'];
     }
     $failures = array();
     foreach ($profiles as $profile_id => $invoice_id) {
         $request = new Am_Paysystem_PaypalApiRequest($this);
         $request->setCc($invoice = $this->getDi()->invoiceTable->load($invoice_id), $cc);
         $request->addPostParameter('METHOD', 'UpdateRecurringPaymentsProfile');
         $request->addPostParameter('PROFILEID', $profile_id);
         $request->addPostParameter('NOTE', 'Update CC info, customer IP: ' . Zend_Controller_Front::getInstance()->getRequest()->getHttpHost());
         $log = Am_Di::getInstance()->invoiceLogRecord;
         $log->title = "updateRecurringPaymentsProfile";
         $log->paysys_id = $this->getId();
         $res = $request->sendRequest($log);
         $log->setInvoice($invoice);
         $log->update();
         if ($res['ACK'] != 'Success') {
             $failures[] = sprintf('CC info was not updated for profile: %s. Got error from paypal: %s', $profile_id, $res['L_SHORTMESSAGE0']);
         }
     }
     if (count($failures)) {
         $result->setFailed($failures);
     } else {
         $result->setSuccess();
     }
 }
Exemplo n.º 12
0
 protected function validate(Am_Paysystem_Result $result)
 {
     if ($this->params['data']['response_code'] != 20000) {
         $result->setFailed(array(___('Refund Failed')));
         return;
     }
     $result->setSuccess();
 }
Exemplo n.º 13
0
 public function validate(Am_Paysystem_Result $result)
 {
     if ($this->params['failure_code']) {
         $result->setFailed($this->params['failure_message']);
     } else {
         $result->setSuccess();
     }
 }
Exemplo n.º 14
0
 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!'));
     }
 }
Exemplo n.º 15
0
 public function run(Am_Paysystem_Result $result)
 {
     $request = $this->plugin->createHttpRequest();
     $paymentsCount = $this->invoice->getPaymentsCount() + 1;
     $vars = array('VPSProtocol' => '3.0', 'TxType' => 'REPEAT', 'Vendor' => $this->getPlugin()->getConfig('login'), 'VendorTxCode' => $this->invoice->public_id . '-AMEMBER-' . $paymentsCount, 'Amount' => number_format($this->invoice->second_total, 2, '.', ''), 'Currency' => $this->invoice->currency ? $this->invoice->currency : 'USD', 'Description' => $this->invoice->getLineDescription(), 'RelatedVPSTxId' => $this->invoice->data()->get('sagepay_vpstxid'), 'RelatedVendorTxCode' => $this->invoice->data()->get('sagepay_vendortxcode'), 'RelatedSecurityKey' => $this->invoice->data()->get('sagepay_securitykey'), 'RelatedTxAuthNo' => $this->invoice->data()->get('sagepay_txauthno'));
     $request->addPostParameter($vars);
     $request->setUrl($this->plugin->getConfig('testing') ? Am_Paysystem_Sagepay::REPEAT_TEST_URL : Am_Paysystem_Sagepay::REPEAT_LIVE_URL);
     $request->setMethod(Am_HttpRequest::METHOD_POST);
     $this->plugin->logRequest($request);
     $response = $request->send();
     $this->plugin->logResponse($response);
     if (!$response->getBody()) {
         $result->setFailed(___("Payment failed") . ":" . ___("Empty response from Sagepay server"));
     } else {
         $res = array();
         foreach (split(PHP_EOL, $response->getBody()) as $line) {
             list($l, $r) = explode('=', $line, 2);
             $res[trim($l)] = trim($r);
         }
         if ($res['Status'] == 'OK') {
             $this->ret = $res;
             $result->setSuccess($this);
             $this->processValidated();
         } else {
             $result->setFailed(___("Payment failed") . ":" . $res['StatusDetail']);
         }
     }
 }
Exemplo n.º 16
0
 public function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount)
 {
     $dpsBillingId = $payment->getInvoice()->data()->get(self::DPS_BILLING_ID);
     if (!$dpsBillingId) {
         return $result->setFailed(array("No saved DPS_BILLING_ID for invoice"));
     }
     $transaction = new Am_Paysystem_Transaction_CreditCard_PaymentExpress_Refund($this, $payment->getInvoice(), $dpsBillingId, $amount);
     $transaction->run($result);
 }
Exemplo n.º 17
0
 public function run(Am_Paysystem_Result $result)
 {
     $this->result = $result;
     $log = $this->getInvoiceLog();
     $request = $this->getRequest();
     $log->add($request);
     $this->paysystemResponse = $this->submitTransaction($request);
     $log->add($this->paysystemResponse);
     if ($this->paysystemResponse->success) {
         try {
             $result->setSuccess($this);
             $this->processValidated();
         } catch (Exception $e) {
             if ($e instanceof PHPUnit_Framework_Error) {
                 throw $e;
             }
             if ($e instanceof PHPUnit_Framework_Asser) {
                 throw $e;
             }
             if (!$result->isFailure()) {
                 $result->setFailed(___("Payment failed"));
             }
             $log->add($e);
         }
     } else {
         if ($errors = $this->paysystemResponse->errors->deepAll()) {
             if (!is_array($errors)) {
                 $errors = array($errors);
             }
             foreach ($errors as $error) {
                 $error_text .= $error->message;
             }
             $result->setFailed("Error: " . $errors);
         } else {
             if ($this->paysystemResponse->transaction->status == 'processor_declined') {
                 $result->setFailed("Declined: " . $this->paysystemResponse->transaction->processorResponseText);
             } else {
                 $result->setFailed("Gateway Rejected: " . $this->paysystemResponse->transaction->gatewayRejectionReason);
             }
         }
     }
 }
Exemplo n.º 18
0
 public function run(Am_Paysystem_Result $result)
 {
     $this->result = $result;
     $log = $this->getInvoiceLog();
     $log->add($this->request);
     try {
         $this->sessionData = call_user_func_array(array($this->getPlugin()->getDispatcher(), 'sessionCreate'), $this->request);
         $this->response = $this->getPlugin()->getDispatcher()->sessionApprove($this->getPlugin()->getConfig('key'), $this->getPlugin()->getConfig('testing'), $this->sessionData['sessionId']);
         $log->add($this->response);
         if ($this->response['status'] == 'APPROVED') {
             $this->processValidated();
             $result->setSuccess();
         }
     } catch (Exception $e) {
         $result->setFailed($e->getMessage());
     }
 }
Exemplo n.º 19
0
 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()));
     }
 }
Exemplo n.º 20
0
 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') {
         $result->setSuccess();
     } else {
         $result->setFailed($return['response_message']);
     }
 }
Exemplo n.º 21
0
 public function cancelAction(Invoice $invoice, $actionName, Am_Paysystem_Result $result)
 {
     $params = array();
     $params['shopid'] = $invoice->public_id;
     $params['reason'] = $actionName;
     $url = self::URL_CANCEL;
     $url .= $this->getConfig('siteid') . "?" . http_build_query($params);
     $request = new Am_HttpRequest($url, Am_HttpRequest::METHOD_GET);
     $response = $request->send();
     if ($response->getBody() == 'ok') {
         $result->setSuccess();
     } else {
         $result->setFailed($response->getBody());
     }
 }
Exemplo n.º 22
0
 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);
     }
 }
Exemplo n.º 23
0
 /**
  * Process payment
  * this is final, override @see process method instead
  * @param Invoice invoice record
  * @param Zend_Controller_Request_Abstract $request user submitted data
  * @param Am_Paysystem_Result $ret may be skipped, then processInvoice will instantiate new
  * @return Am_Paysystem_Result
  */
 public function processInvoice(Invoice $invoice, Am_Request $request, Am_Paysystem_Result &$ret = null)
 {
     if (null == $ret) {
         $ret = new Am_Paysystem_Result();
     }
     $this->_setInvoice($invoice);
     $errors = $this->isNotAcceptableForInvoice($invoice);
     if (null != $errors) {
         return $ret->setFailed($errors);
     }
     try {
         $this->_process($invoice, $request, $ret);
     } catch (Am_Exception_Redirect $e) {
         // pass
     } catch (Am_Exception $e) {
         $this->log("Exception in " . __METHOD__, $e);
         $ret->setFailed(array(___("Payment error: ") . $e->getPublicError()));
     }
     return $ret;
 }
Exemplo n.º 24
0
 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') {
         $result->setFailed('Transaction was not refunded. Got error from paypal: ' . $res['L_SHORTMESSAGE0']);
         return;
     }
     $result->setSuccess();
     // We will not add refund record here because it will be handeld by IPN script.
 }
Exemplo n.º 25
0
 public function cancelAction(Invoice $invoice, $actionName, Am_Paysystem_Result $result)
 {
     $this->invoice = $invoice;
     list($payment) = $invoice->getPaymentRecords();
     $params = array('key' => $this->getConfig('key'), 'ref' => $payment->receipt_id, 'uid' => $payment->user_id, 'type' => 2);
     $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) {
         $invoice->setCancelled();
         $result->setSuccess();
         return;
     }
     $result->setFailed($res['errors']);
 }
Exemplo n.º 26
0
 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);
 }
Exemplo n.º 27
0
 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!'));
     }
 }
Exemplo n.º 28
0
 public function run(Am_Paysystem_Result $result)
 {
     $this->result = $result;
     $log = $this->getInvoiceLog();
     try {
         $soapClient = new SoapClient_Cybersource($this->getPlugin());
     } catch (Exception $ex) {
         throw new Am_Exception_InternalError("Cannot create soapclient object: " . $ex->getMessage());
     }
     $soapResult = $soapClient->runTransaction($this->soapData);
     $this->response = json_decode(json_encode($soapResult), true);
     $log->add($this->response);
     $this->validateResponseStatus($this->result);
     if ($this->result->isFailure()) {
         return;
     }
     try {
         $this->parseResponse();
         $this->validate();
         if ($this->result->isSuccess()) {
             $this->processValidated();
         }
     } catch (Exception $e) {
         if ($e instanceof PHPUnit_Framework_Error) {
             throw $e;
         }
         if ($e instanceof PHPUnit_Framework_Asser) {
             throw $e;
         }
         if (!$result->isFailure()) {
             $result->setFailed(___("Payment failed"));
         }
         $log->add($e);
     }
 }
Exemplo n.º 29
0
 public function validateResponseStatus(Am_Paysystem_Result $result)
 {
     if ($this->response->getStatus() != 200) {
         $result->setFailed(array("Received invalid response from payment server: " . $this->response->getStatus()));
     }
 }
Exemplo n.º 30
0
 public function run(Am_Paysystem_Result $result)
 {
     $subscriptionid = $this->invoice->data()->get(Am_Paysystem_Epay::SUBSCRIPTIONID);
     $req = $this->plugin->APIRequest('subscription', 'authorize', $vars = array('merchantnumber' => $this->plugin->getConfig('id'), 'subscriptionid' => $subscriptionid, 'orderid' => $this->invoice->public_id . "-" . $this->invoice->getPaymentsCount(), 'amount' => $this->invoice->second_total * 100, 'currency' => Am_Currency::getNumericCode($this->invoice->currency), 'instantcapture' => 1, 'description' => 'Recurring payment for invoice ' . $this->invoice->public_id, 'email' => $this->invoice->getEmail(), 'ipaddress' => $this->invoice->getUser()->remote_addr));
     $log = $this->getInvoiceLog();
     $log->add(print_r($vars, true));
     $this->ret = $this->plugin->getResponseXML($req);
     $log->add(print_r($this->ret, true));
     if ($this->ret->authorizeResponse->authorizeResult != 'true') {
         $result->setFailed(___("Payment failed") . ":" . $this->plugin->getEpayError($this->ret->authorizeResponse->epayresponse));
     } else {
         $result->setSuccess($this);
         $this->processValidated();
     }
 }