Example #1
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.
 }
Example #2
0
 public function _initSetupForm(Am_Form_Setup $form)
 {
     Am_Paysystem_PaypalApiRequest::initSetupForm($form);
 }
Example #3
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();
     }
 }
Example #4
0
 function cancelAction(Invoice $invoice, $actionName, Am_Paysystem_Result $result)
 {
     $log = Am_Di::getInstance()->invoiceLogRecord;
     $log->title = "cancelRecurringPaymentProfile";
     $log->paysys_id = $this->getId();
     $apireq = new Am_Paysystem_PaypalApiRequest($this);
     $apireq->cancelRecurringPaymentProfile($invoice, $invoice->data()->get(self::PAYPAL_PROFILE_ID));
     $vars = $apireq->sendRequest($log);
     $log->setInvoice($invoice);
     $log->update();
     if ($vars['ACK'] != 'Success') {
         throw new Am_Exception_InputError('Transaction was not cancelled. Got error from paypal: ' . $vars['L_SHORTMESSAGE0']);
     }
     $invoice->setCancelled(true);
     $result->setSuccess();
 }
 public function expressCheckoutAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs)
 {
     $token = $request->getFiltered('token');
     if (!$token) {
         throw new Am_Exception_InputError("No required [token] provided, internal error");
     }
     $log = $this->getDi()->invoiceLogRecord;
     $log->title = "";
     $log->paysys_id = $this->getId();
     if ($request->getInt('do')) {
         $invoice = current($this->getDi()->invoiceTable->findByData(self::PAYPAL_EXPRESS_TOKEN, $token));
         if (!$invoice) {
             throw new Am_Exception_InternalError("Could not find invoice by token [{$token}]");
         }
         $this->_setInvoice($invoice);
         $log->setInvoice($invoice);
         if ($invoice->first_total > 0) {
             // bill initial amount @todo free trial
             $log->title .= " doExpressCheckout";
             $apireq = new Am_Paysystem_PaypalApiRequest($this);
             $apireq->doExpressCheckout($invoice, $token, $request->getFiltered('PayerID'));
             $vars = $apireq->sendRequest($log);
             $transaction = new Am_Paysystem_Transaction_PayPalExpress_DoExpressCheckout($this, $vars);
             $transaction->setInvoice($invoice);
             $transaction->process();
         }
         if ($invoice->rebill_times) {
             $log->title .= " createRecurringPaymentProfile";
             $apireq = new Am_Paysystem_PaypalApiRequest($this);
             $apireq->createRecurringPaymentProfile($invoice, null, $token, $request->getFiltered('PayerID'));
             $vars = $apireq->sendRequest($log);
             if ($vars['ACK'] != 'Success') {
                 $this->logError("Not Success response to CreateRecurringPaymentProfile request", $vars);
             } else {
                 $invoice->data()->set(self::PAYPAL_PROFILE_ID, $vars['PROFILEID'])->update();
                 if ($invoice->first_total <= 0) {
                     $transaction = new Am_Paysystem_Transaction_PayPalExpress_CreateRecurringPaymentProfile($this, $vars);
                     $transaction->setInvoice($invoice);
                     $transaction->process();
                 }
             }
         }
         return Am_Controller::redirectLocation($this->getReturnUrl());
     } else {
         $log->title .= " getExpressCheckoutDetails";
         $apireq = new Am_Paysystem_PaypalApiRequest($this);
         $apireq->getExpressCheckoutDetails($token);
         $vars = $apireq->sendRequest($log);
         $invoiceId = filterId(get_first(@$vars['INVNUM'], @$vars['L_PAYMENTREQUEST_0_INVNUM'], $this->getDi()->session->paypal_invoice_id));
         if (!$invoiceId || !($invoice = $this->getDi()->invoiceTable->findBySecureId($invoiceId, 'paypal'))) {
             throw new Am_Exception_InputError("Could not find invoice related to given payment. Internal error. Your account was not billed, please try again");
         }
         $log->setInvoice($invoice);
         $log->update();
         $this->_setInvoice($invoice);
         /* @var $invoice Invoice */
         if ($invoice->isPaid()) {
             return Am_Controller::redirectLocation($this->getReturnUrl());
         }
         $invoice->data()->set(self::PAYPAL_EXPRESS_TOKEN, $token)->update();
         $view = new Am_View();
         $view->invoice = $invoice;
         $view->url = $this->getPluginUrl(self::PAYPAL_EXPRESS_CHECKOUT);
         $view->hidden = array('do' => '1', 'token' => $request->getFiltered('token'), 'PayerID' => $request->getFiltered('PayerID'));
         $view->display("payment-confirm.phtml");
     }
 }