Example #1
0
    function showCreditTab() {
        if ($this->login_type == 'subscriber' && in_array("blocked",$this->groups)) {
            return false;
        }

        $task        = $_REQUEST['task'];
        $issuer      = $_REQUEST['issuer'];
        $prepaidCard = $_REQUEST['prepaidCard'];
        $prepaidId   = $_REQUEST['prepaidId'];

        $_done       = false;

        if ($issuer) {
            print "
            <tr>
            <td colspan=2 align=left> ";

            if ($issuer=='subscriber'){
                if ($prepaidCard && $prepaidId) {
                    if ($result = $this->addBalanceSubscriber($prepaidCard,$prepaidId)) {
                        print "<p><font color=green>";
                        printf (_("Old balance was %s, new balance is %s. "),$result->old_balance, $result->new_balance);
                        print "</font>";
                        $_done=true;
                    }
                }
            } else if ($issuer=='reseller' || $issuer=='admin') {
                if ($_REQUEST['task'] == 'change_balance') {
                    $description = $_REQUEST['description'];
                    $value       = $_REQUEST['value'];

                    if (strlen($value) && $result = $this->addBalanceReseller($value,$description)) {
                        print "<p><font color=green>";
                        printf (_("Old balance was %s, new balance is %s. "),$result->old_balance, $result->new_balance);
                        print "</font>";
                        $_done=true;
                    }
                } else if ($_REQUEST['task'] == 'refund') {
                    $transaction = json_decode(base64_decode($_REQUEST['transaction']));
                    printf ("Refunding transaction id %s in value of %s", $transaction->id, $transaction->value);

                    require('cc_processor.php');
                    $ccp = new CreditCardProcessor();
                    $refund_results = $ccp->refundPayment($transaction->id);

                    if(count($refund_results['error']) > 0 ){
                        printf ("<p><font color=red>Error %d: %s (%s)</font>",$refund_results['error']['error_code'], $refund_results['error']['desc'], $refund_results['error']['short_message']);
                    } else {
                        printf ("<p>Transaction %s refunded with %s: %s",$transaction->id, $refund_results['success']['desc']->RefundTransactionID,$refund_results['success']['desc']->GrossRefundAmount->_value);
                        $description=sprintf("Refund %s with %s",$transaction->id, $refund_results['success']['desc']->RefundTransactionID);
                        if ($result = $this->addBalanceReseller(-$transaction->value,$description)) {
                            print "<p><font color=green>";
                            printf (_("Old balance was %s, new balance is %s. "),$result->old_balance, $result->new_balance);
                            print "</font>";
                            $_done=true;
                        }
                    }
                }
            }

            if ($_done && $_REQUEST['notify']) {
                $subject=sprintf ("SIP Account %s balance update",$this->account);

                $body="Your SIP Account balance has been updated. ".
                "For more details go to $this->sip_settings_page?tab=credit";

                if (mail($this->email, $subject, $body, "From: $this->support_email")) {
                    printf (_("Subscriber has been notified at %s."), $this->email);
                }
            }

            print "
            </td>
            </tr>
            ";
        }

        $this->getPrepaidStatus();

        if ($this->prepaidAccount) {
            $chapter=sprintf(_("Current Balance"));
            $this->showChapter($chapter);

            print "
            <div class=row-fluid>
            <div class=span12>";
            print _("Your current balance is");
            print ": ";
            printf ("%.2f %s ",$this->prepaidAccount->balance,$this->currency);
            print "</div>
            </div>
            ";

            $this->showChangeBalanceReseller();
            $this->showChangeBalanceSubscriber();
            $this->showBalanceHistory();

        }
    }
Example #2
0
 function processPayment()
 {
     dprint("processPayment()");
     if (!$this->setEnvironment()) {
         print "Fail to set environment!";
         return false;
     }
     // return sucess and set relevant data from the transaction to variables belonging to the class
     $errors = array();
     $pp_return = array();
     $_TransactionKey = filter_var($_POST['transactionKey'], FILTER_SANITIZE_STRING);
     if ($_TransactionKey == '') {
         $pp_return = array('error' => array('field' => 'key', 'desc' => _('Missing transaction key')));
     } else {
         if (CreditCardProcessor::transaction_exists($_TransactionKey) == true) {
             $pp_return = array('error' => array('field' => 'reload', 'desc' => _('Transaction already exists. Do not press the browser reload button.')));
         } else {
             $pid = ProfileHandler::generateID();
             $handler =& ProfileHandler_Array::getInstance(array('username' => $this->pp_username, 'certificateFile' => null, 'subject' => null, 'environment' => $this->environment));
             $profile = new APIProfile($pid, $handler);
             $profile->setAPIUsername($this->pp_username);
             $profile->setAPIPassword($this->pricepp_pass);
             $profile->setSignature($this->pp_signature);
             $profile->setCertificateFile(null);
             $profile->setEnvironment($this->environment);
             $dp_request =& PayPal::getType('DoDirectPaymentRequestType');
             $paymentType = $this->transaction_type;
             $firstName = filter_var($_POST['firstName'], FILTER_SANITIZE_STRING);
             $lastName = filter_var($_POST['lastName'], FILTER_SANITIZE_STRING);
             $emailAddress = filter_var($_POST['emailAddress'], FILTER_SANITIZE_EMAIL);
             $creditCardType = filter_var($_POST['creditCardType'], FILTER_SANITIZE_STRING);
             $creditCardNumber = filter_var($_POST['creditCardNumber'], FILTER_SANITIZE_NUMBER_INT);
             $expDateMonth = filter_var($_POST['expDateMonth'], FILTER_SANITIZE_NUMBER_INT);
             // Month must be padded with leading zero
             $padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT);
             $expDateYear = filter_var($_POST['expDateYear'], FILTER_SANITIZE_NUMBER_INT);
             $cvv2Number = filter_var($_POST['cvv2Number'], FILTER_SANITIZE_STRING);
             $address1 = filter_var($_POST['address1'], FILTER_SANITIZE_STRING);
             $address2 = filter_var($_POST['address2'], FILTER_SANITIZE_STRING);
             $city = filter_var($_POST['city'], FILTER_SANITIZE_STRING);
             $state = filter_var($_POST['state'], FILTER_SANITIZE_STRING);
             $zip = filter_var($_POST['zip'], FILTER_SANITIZE_STRING);
             $country = filter_var($_POST['country'], FILTER_SANITIZE_STRING);
             $this->total = $_POST['amount'];
             // Populate SOAP request information
             // Payment details
             $OrderTotal =& PayPal::getType('BasicAmountType');
             $OrderTotal->setattr('currencyID', 'USD');
             $OrderTotal->setval($this->total, 'iso-8859-1');
             $PaymentDetails =& PayPal::getType('PaymentDetailsType');
             $PaymentDetails->setOrderTotal($OrderTotal);
             $shipTo =& PayPal::getType('AddressType');
             $shipTo->setName($firstName . ' ' . $lastName);
             $shipTo->setStreet1($address1);
             $shipTo->setStreet2($address2);
             $shipTo->setCityName($city);
             $shipTo->setStateOrProvince($state);
             $shipTo->setCountry($country);
             $shipTo->setPostalCode($zip);
             $PaymentDetails->setShipToAddress($shipTo);
             $dp_details =& PayPal::getType('DoDirectPaymentRequestDetailsType');
             $dp_details->setPaymentDetails($PaymentDetails);
             // Credit Card info
             $card_details =& PayPal::getType('CreditCardDetailsType');
             $card_details->setCreditCardType($creditCardType);
             $card_details->setCreditCardNumber($creditCardNumber);
             $card_details->setExpMonth($padDateMonth);
             $card_details->setExpYear($expDateYear);
             $card_details->setCVV2($cvv2Number);
             $payer =& PayPal::getType('PayerInfoType');
             $person_name =& PayPal::getType('PersonNameType');
             $person_name->setFirstName($firstName);
             $person_name->setLastName($lastName);
             $payer->setPayerName($person_name);
             $payer->setPayerCountry($country);
             $payer->setAddress($shipTo);
             $card_details->setCardOwner($payer);
             $dp_details->setCreditCard($card_details);
             $dp_details->setIPAddress($_SERVER['SERVER_ADDR']);
             // set our session ID to be sent with PayPal Request
             if ($this->note) {
                 $_id = $this->note . ' ' . $_TransactionKey;
             } else {
                 $_id = $_TransactionKey;
             }
             $dp_details->setMerchantSessionId($_id);
             //$dp_details->setMerchantSessionId($_TransactionKey);
             $dp_details->setPaymentAction($paymentType);
             $dp_request->setDoDirectPaymentRequestDetails($dp_details);
             $caller =& PayPal::getCallerServices($profile);
             $this->logger->_log("CC Profile: " . print_r($profile, true) . "");
             $this->logger->_log("Request Details: " . print_r($dp_details, true) . "");
             // Execute SOAP request
             $response = $caller->DoDirectPayment($dp_request);
             $this->logger->_log("Response Details: " . print_r($response, true) . "");
             if (!method_exists($response, 'getAck')) {
                 $error = 'Response is a ' . get_class($response) . ' object:';
                 if (method_exists($response, 'getMessage')) {
                     $_log .= "\n  getMessage() => " . strval($response->getMessage());
                 }
                 /*
                                 foreach(get_object_vars($response) as $k=>$v){
                     $_log.="\n\xA0\xA0$k => ".strval($v);
                 }
                 */
                 // Finish handling the error, etc. For example,
                 $pp_return = array('error' => array('field' => 'Card Processing', 'desc' => 'Unknown Processing Error'));
                 $log = sprintf("Error: SIP Account %s - CC transaction failed to process: %s", $this->account, $_log);
                 syslog(LOG_NOTICE, $log);
             } else {
                 $ack = $response->getAck();
                 if ($ack == "Success") {
                     $pp_return = array('success' => array('field' => 'Card Processing', 'desc' => $response));
                 } else {
                     $pp_return = array('error' => array('field' => 'Card Processing', 'desc' => $response->Errors->LongMessage, 'short_message' => $response->Errors->ShortMessage, 'error_code' => $response->Errors->ErrorCode, 'correlation_id' => $response->CorrelationID, 'card_type' => $creditCardType, 'first_name' => $firstName, 'last_name' => $lastName));
                     $log = sprintf("%s card of %s %s - Transaction %s Error: %s/%s (%s)", $creditCardType, $firstName, $lastName, $response->CorrelationID, $response->Errors->ErrorCode, $response->Errors->ShortMessage, $response->Errors->LongMessage);
                     $this->logger->_log($log);
                 }
             }
         }
     }
     return $pp_return;
 }