示例#1
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $config =& CRM_Core_Config::singleton();
     if ($params['api_environment'] == 'live') {
         $savePath = $config->paymentCertPath['live'];
     } else {
         $savePath = $config->paymentCertPath['test'];
     }
     $certName = $this->controller->exportValue($this->_name, 'uploadFile');
     $cert = file_get_contents($certName);
     require_once 'Services/PayPal.php';
     require_once 'Services/PayPal/Profile/Handler/File.php';
     require_once 'Services/PayPal/Profile/API.php';
     $handler =& ProfileHandler_File::getInstance(array('path' => $savePath, 'charset' => 'iso-8859-1'));
     $pid = ProfileHandler::generateID();
     $profile =& new APIProfile($pid, $handler);
     $certFile = "{$savePath}{$pid}.cert";
     $fd = fopen($certFile, "w");
     if (!$fd) {
         CRM_Core_Error::fatal(ts("Could not open %1 file for writing", array(1 => $certFile)));
     }
     if (!fwrite($fd, $cert)) {
         CRM_Core_Error::fatal("Could not write into {$certFile}<p>");
     }
     if (!fclose($fd)) {
         CRM_Core_Error::fatal("Could not close {$certFile}<p>");
     }
     $profile->setAPIUsername($params['api_username']);
     $profile->setSubject($params['api_subject']);
     $profile->setEnvironment($params['api_environment']);
     $profile->setCertificateFile($certFile);
     $result = $profile->save();
     if (Services_PayPal::isError($result)) {
         CRM_Core_Error::statusBounce("Could not create new profile: " . $result->getMessage());
     } else {
         if ($params['api_environment'] == 'live') {
             $name = 'CIVICRM_CONTRIBUTE_PAYMENT_KEY';
         } else {
             $name = 'CIVICRM_CONTRIBUTE_PAYMENT_TEST_KEY';
         }
         $message = ts('Your %1 value is: "%2". This value must be entered in the Payment Processor section of the CiviCRM configuration file.', array(1 => $name, 2 => $pid));
         CRM_Core_Session::setStatus($message);
     }
 }
示例#2
0
 function ipn(&$BL)
 {
     if ($_POST['pp'] == "paypalwpp") {
         $this->item_number = $_POST['item_number'];
         $this->transaction_id = 0;
         $this->payment_status = '';
         $pp_vals = $BL->pp_vals->getByKey("paypalwpp");
         $temp = $BL->orphan_orders->hasAnyOne(array("WHERE `item_number`=" . intval($this->item_number)));
         $O_order = array();
         foreach ($BL->orphan_order_datas->find(array("WHERE `orphan_order_id`=" . intval($temp['orphanorder_id']))) as $data) {
             $O_order[$data['orphan_order_field']] = $data['orphan_order_value'];
         }
         if (count($O_order)) {
             $amount = number_format($O_order['gross_amount'], 2);
         } else {
             $invoice = $BL->invoices->get("WHERE `invoice_no`=" . intval($this->item_number));
             $amount = number_format($invoice[0]['gross_amount'], 2);
         }
         require_once 'PayPal.php';
         require_once 'PayPal/Profile/API.php';
         require_once 'PayPal/Profile/Handler.php';
         require_once 'PayPal/Profile/Handler/Array.php';
         require_once 'PayPal/Type/DoDirectPaymentRequestType.php';
         require_once 'PayPal/Type/DoDirectPaymentRequestDetailsType.php';
         require_once 'PayPal/Type/DoDirectPaymentResponseType.php';
         // Add all of the types
         require_once 'PayPal/Type/BasicAmountType.php';
         require_once 'PayPal/Type/PaymentDetailsType.php';
         require_once 'PayPal/Type/AddressType.php';
         require_once 'PayPal/Type/CreditCardDetailsType.php';
         require_once 'PayPal/Type/PayerInfoType.php';
         require_once 'PayPal/Type/PersonNameType.php';
         // Ack related constants
         define('ACK_SUCCESS', 'Success');
         define('ACK_SUCCESS_WITH_WARNING', 'SuccessWithWarning');
         // Refund related constants
         define('REFUND_PARTIAL', 'Partial');
         define('REFUND_FULL', 'Full');
         // Profile
         if ($this->demo_mode) {
             define('ENVIRONMENT', 'sandbox');
         } else {
             define('ENVIRONMENT', 'live');
         }
         define('UNITED_STATES', 'US');
         $dummy = @new APIProfile();
         $environments = $dummy->getValidEnvironments();
         $handler =& ProfileHandler_Array::getInstance(array('username' => $pp_vals['paypalwpp_apiUsername'], 'certificateFile' => null, 'subject' => null, 'environment' => ENVIRONMENT));
         $pid = ProfileHandler::generateID();
         $profile = new APIProfile($pid, $handler);
         $profile->setAPIUsername($pp_vals['paypalwpp_apiUsername']);
         $profile->setAPIPassword($pp_vals['paypalwpp_apiPassword']);
         if (is_file($pp_vals['paypalwpp_certFile'])) {
             $profile->setCertificateFile($pp_vals['paypalwpp_certFile']);
         }
         $profile->setSignature($pp_vals['paypalwpp_signature']);
         $profile->setEnvironment(ENVIRONMENT);
         $caller =& PayPal::getCallerServices($profile);
         $_SESSION['APIProfile'] = $profile;
         $_SESSION['caller'] = $caller;
         $dp_request =& PayPal::getType('DoDirectPaymentRequestType');
         /**
          * Get posted request values
          */
         $paymentType = 'Sale';
         $firstName = $_POST['paypalwpp_firstName'];
         $lastName = $_POST['paypalwpp_lastName'];
         $creditCardType = $_POST['paypalwpp_creditCardType'];
         $creditCardNumber = $_POST['paypalwpp_creditCardNumber'];
         $expDateMonth = $_POST['paypalwpp_expDateMonth'];
         $padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT);
         $expDateYear = $_POST['paypalwpp_expDateYear'];
         $cvv2Number = $_POST['paypalwpp_cvv2Number'];
         $address1 = $_POST['paypalwpp_address1'];
         $address2 = $_POST['paypalwpp_address2'];
         $city = $_POST['paypalwpp_city'];
         $state = $_POST['paypalwpp_state'];
         $zip = $_POST['paypalwpp_zip'];
         $amount = $amount;
         // Populate SOAP request information
         // Payment details
         $OrderTotal =& PayPal::getType('BasicAmountType');
         $OrderTotal->setattr('currencyID', 'USD');
         $OrderTotal->setval($amount, '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(UNITED_STATES);
         $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(UNITED_STATES);
         $payer->setAddress($shipTo);
         $card_details->setCardOwner($payer);
         $dp_details->setCreditCard($card_details);
         $dp_details->setIPAddress($_SERVER['SERVER_ADDR']);
         $dp_details->setPaymentAction($paymentType);
         $dp_request->setDoDirectPaymentRequestDetails($dp_details);
         $caller =& PayPal::getCallerServices($profile);
         $response = $caller->DoDirectPayment($dp_request);
         $ack = $response->getAck();
         $this->payment_status = $ack;
         $this->transaction_id = $response->TransactionID;
         if (!empty($this->item_number) && !empty($this->transaction_id) && ($this->payment_status == ACK_SUCCESS || $this->payment_status == ACK_SUCCESS_WITH_WARNING)) {
             $BL->invoices->processTransaction($this->item_number, $this->transaction_id);
             return true;
         }
     }
     return false;
 }
require_once 'PayPal/Profile/Handler/Array.php';
require_once 'lib/api_form_validators.inc.php';
require_once 'lib/functions.inc.php';
require_once 'lib/constants.inc.php';
require_once 'SampleLogger.php';
session_start();
$dummy = @new APIProfile();
$environments = $dummy->getValidEnvironments();
$was_submitted = false;
$logger = new SampleLogger('WebPaymentPro.php', PEAR_LOG_DEBUG);
$logger->_log(print_r($_POST, true));
if (isset($_POST['submitted'])) {
    $logger->_log('submitted');
    unset($_POST['submitted']);
    $handler =& ProfileHandler_Array::getInstance(array('username' => $_POST['apiUsername'], 'certificateFile' => null, 'subject' => null, 'environment' => ENVIRONMENT));
    $pid = ProfileHandler::generateID();
    $profile = new APIProfile($pid, $handler);
    $logger->_log('Profile: ' . print_r($profile, true));
    $save_file;
    if (isset($_FILES['certFile'])) {
        // Use my account
        if (!file_exists($_FILES['certFile']['tmp_name'])) {
            $errors['certFile'] = "You must provide a Certificate for the profile";
        } else {
            if (!is_uploaded_file($_FILES['certFile']['tmp_name'])) {
                $errors['certFile'] = "Invalid file upload, cannot save profile";
            }
        }
        // Defined in lib/functions.inc.php
        $cert_save_path = _getProfileCertSavePath();
        $logger->_log('cert_save_path is ' . $cert_save_path);
示例#4
0
 function save($data)
 {
     $data = $this->udm->getData();
     foreach ($data as $key => $value) {
         if ($field = $this->checkPrefix($key)) {
             $plugin[$field] = $value;
         }
     }
     $options = $this->getOptions();
     require_once 'PayPal.php';
     require_once 'PayPal/Profile/API.php';
     require_once 'PayPal/Profile/Handler.php';
     require_once 'PayPal/Profile/Handler/Array.php';
     require_once 'PayPal/Type/DoDirectPaymentRequestType.php';
     require_once 'PayPal/Type/DoDirectPaymentRequestDetailsType.php';
     require_once 'PayPal/Type/DoDirectPaymentResponseType.php';
     require_once 'PayPal/Type/BasicAmountType.php';
     require_once 'PayPal/Type/PaymentDetailsType.php';
     require_once 'PayPal/Type/AddressType.php';
     require_once 'PayPal/Type/CreditCardDetailsType.php';
     require_once 'PayPal/Type/PayerInfoType.php';
     require_once 'PayPal/Type/PersonNameType.php';
     $pid =& ProfileHandler::generateID();
     $handler =& ProfileHandler_Array::getInstance(array('username' => $options['api_username'], 'password' => $options['api_password'], 'certificateFile' => $options['cert_file'], 'subject' => null, 'environment' => $options['environment']));
     $profile =& APIProfile::getInstance($pid, $handler);
     $dp_request =& PayPal::getType('DoDirectPaymentRequestType');
     $firstName = $data['First_Name'];
     $lastName = $data['Last_Name'];
     $creditCardType = $plugin['cc_type'];
     $creditCardNumber = $plugin['cc_number'];
     $expDateMonth = $plugin['cc_expiration']['m'];
     // Month must be padded with leading zero
     $padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT);
     $expDateYear = $plugin['cc_expiration']['Y'];
     $cvv2Number = $plugin['cc_cvv2'];
     $address1 = $data['Street'];
     $address2 = isset($data['Street_1']) ? $data['Street_1'] : null;
     $city = $data['City'];
     $state = $data['State'];
     $zip = $data['Zip'];
     $amount = $plugin['amount'];
     $OrderTotal =& PayPal::getType('BasicAmountType');
     $OrderTotal->setattr('currencyID', 'USD');
     $OrderTotal->setval($amount, '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('US');
     $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('US');
     $payer->setAddress($shipTo);
     if (isset($data['Email'])) {
         $payer->setPayer($data['Email']);
     }
     $card_details->setCardOwner($payer);
     $dp_details->setCreditCard($card_details);
     $dp_details->setIPAddress($_SERVER['SERVER_ADDR']);
     $dp_details->setPaymentAction('Sale');
     $dp_request->setDoDirectPaymentRequestDetails($dp_details);
     $caller =& PayPal::getCallerServices($profile);
     if (PEAR::isError($caller)) {
         trigger_error($caller->getMessage());
         return false;
     }
     $response = $caller->DoDirectPayment($dp_request);
     $ack = $response->getAck();
     define('ACK_SUCCESS', 'Success');
     define('ACK_SUCCESS_WITH_WARNING', 'SuccessWithWarning');
     switch ($ack) {
         case ACK_SUCCESS:
         case ACK_SUCCESS_WITH_WARNING:
             if (isset($options['response']) && $options['response']) {
                 $response_code = 'Transaction ID: ' . $response->getTransactionID() . "\n" . 'Completed AVS Code: ' . $response->getAVSCode() . "\n" . 'CVV2 Code: ' . $response->getCVV2Code();
                 require_once 'AMP/System/User/Profile/Profile.php';
                 $profile =& new AMP_System_User_Profile($this->dbcon, $this->udm->uid);
                 if ($profile->hasData()) {
                     $update = array($options['response'] => $response_code);
                     $profile->mergeData($update);
                     $profile->save();
                 } else {
                     trigger_error('cannot update profile with paypal response: ' . $response_code);
                 }
             }
             return true;
         default:
             require_once 'PayPal/Type/AbstractResponseType.php';
             require_once 'PayPal/Type/ErrorType.php';
             require_once 'PayPal/Type/DoDirectPaymentResponseType.php';
             $errors =& $response->getErrors();
             if (!is_array($errors)) {
                 $errors = array($errors);
             }
             foreach ($errors as $error) {
                 trigger_error($error->getShortMessage() . ' : ' . $error->getLongMessage());
                 $flash =& AMP_System_Flash::instance();
                 $flash->add_error($error->getLongMessage());
             }
     }
     return false;
 }
示例#5
0
 public function purchase()
 {
     // Note, we used to add extensions/ to include_path here, that should either
     // be standardized in Loader or we need to load more files here to make
     // up for whatever the PayPal code would otherwise try to load
     require_once 'extensions/PayPal.php';
     require_once 'extensions/PayPal/Profile/Handler/Array.php';
     require_once 'extensions/PayPal/Profile/API.php';
     require_once 'extensions/PayPal/Type/DoDirectPaymentRequestType.php';
     require_once 'extensions/PayPal/Type/DoDirectPaymentRequestDetailsType.php';
     require_once 'extensions/PayPal/Type/DoDirectPaymentResponseType.php';
     //  Add all of the types
     require_once 'extensions/PayPal/Type/BasicAmountType.php';
     require_once 'extensions/PayPal/Type/PaymentDetailsType.php';
     require_once 'extensions/PayPal/Type/AddressType.php';
     require_once 'extensions/PayPal/Type/CreditCardDetailsType.php';
     require_once 'extensions/PayPal/Type/PayerInfoType.php';
     require_once 'extensions/PayPal/Type/PersonNameType.php';
     require_once 'extensions/PayPal/CallerServices.php';
     $environment = $this->live ? 'live' : 'sandbox';
     $dp_request = new DoDirectPaymentRequestType();
     $OrderTotal = new BasicAmountType();
     $OrderTotal->setattr('currencyID', 'USD');
     $OrderTotal->setval($this->amount, 'iso-8859-1');
     $PaymentDetails = new PaymentDetailsType();
     $PaymentDetails->setOrderTotal($OrderTotal);
     $shipTo = new AddressType();
     $shipTo->setName($this->firstName . ' ' . $this->lastName);
     $shipTo->setStreet1($this->address1);
     $shipTo->setStreet2($this->address2);
     $shipTo->setCityName($this->city);
     $shipTo->setStateOrProvince($this->state);
     $shipTo->setCountry('US');
     $shipTo->setPostalCode($this->zip);
     $PaymentDetails->setShipToAddress($shipTo);
     $dp_details = new DoDirectPaymentRequestDetailsType();
     $dp_details->setPaymentDetails($PaymentDetails);
     // Credit Card info
     $card_details = new CreditCardDetailsType();
     $card_details->setCreditCardType($this->creditCardType);
     $card_details->setCreditCardNumber($this->creditCardNumber);
     $card_details->setExpMonth($this->expirationMonth);
     $card_details->setExpYear($this->expirationYear);
     $card_details->setCVV2($this->cvv2Number);
     $payer = new PayerInfoType();
     $person_name = new PersonNameType();
     $person_name->setFirstName($this->firstName);
     $person_name->setLastName($this->lastName);
     $payer->setPayerName($person_name);
     $payer->setPayerCountry('US');
     $payer->setAddress($shipTo);
     $card_details->setCardOwner($payer);
     $dp_details->setCreditCard($card_details);
     $dp_details->setIPAddress($_SERVER['SERVER_ADDR']);
     $dp_details->setPaymentAction('Sale');
     $dp_request->setDoDirectPaymentRequestDetails($dp_details);
     $handler = ProfileHandler_Array::getInstance(array('username' => $this->apiUsername, 'certificateFile' => null, 'subject' => null, 'environment' => $environment));
     $pid = ProfileHandler::generateID();
     $profile = new APIProfile($pid, $handler);
     $profile->setAPIUsername($this->apiUsername);
     $profile->setAPIPassword($this->apiPassword);
     $profile->setSignature($this->apiSignature);
     $profile->setEnvironment($environment);
     $caller = new CallerServices($profile);
     $response = $caller->DoDirectPayment($dp_request);
     if (PayPal::isError($response)) {
         Site::getPage()->addWarning($response->message);
         return false;
     }
     if ($response->Ack == 'Success') {
         return true;
     }
     if (is_array($response->Errors)) {
         foreach ($response->Errors as $error) {
             Site::getPage()->addWarning($error->LongMessage);
         }
     } else {
         Site::getPage()->addWarning($response->Errors->LongMessage);
     }
     return false;
 }
示例#6
0
 function refundPayment($transaction_id, $type = 'Full', $amount = '', $note = '')
 {
     if (!$this->setEnvironment()) {
         return false;
     }
     if (!$transaction_id) {
         return false;
     }
     if (!$note) {
         $note = sprintf('Refund %s', $transaction_id);
     }
     $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);
     $ref_details =& PayPal::getType('RefundTransactionRequestType');
     $ref_details->setVersion("51.0");
     $transactionID = filter_var($transaction_id, FILTER_SANITIZE_STRING);
     $refundType = filter_var($type, FILTER_SANITIZE_STRING);
     $refundAmount = filter_var($amount, FILTER_SANITIZE_STRING);
     $refundNote = filter_var($note, FILTER_SANITIZE_STRING);
     $ref_details->setTransactionID($transactionID, 'iso-8859-1');
     $ref_details->setRefundType($refundType, 'iso-8859-1');
     $ref_details->setAmount($refundAmount, 'iso-8859-1');
     $ref_details->setMemo($refundNote, 'iso-8859-1');
     $caller =& PayPal::getCallerServices($profile);
     $this->logger->_log("Refund Profile: " . print_r($profile, true) . "");
     $this->logger->_log("Refund Request Details: " . print_r($ref_details, true) . "");
     $response = $caller->RefundTransaction($ref_details);
     $this->logger->_log("Refund Response Details: " . print_r($response, true) . "");
     $ack = $response->getAck();
     $ref_return = array();
     if ($ack == 'Success') {
         $ref_return = array('success' => array('field' => 'Refund Processing', 'desc' => $response));
     } else {
         $ref_return = array('error' => array('field' => 'Refund Processing', 'desc' => $response->Errors->LongMessage, 'short_message' => $response->Errors->ShortMessage, 'error_code' => $response->Errors->ErrorCode, 'correlation_id' => $response->CorrelationID));
     }
     return $ref_return;
 }
示例#7
0
 private function populateApiCredentials()
 {
     $environment = $this->configuration['paypal']['environment'];
     $APIUsername = $this->configuration['paypal']['APIUsername'];
     $APIPassword = $this->configuration['paypal']['APIPassword'];
     $APISignature = $this->configuration['paypal']['APISignature'];
     $APICertificate = $this->configuration['paypal']['APICertificate'];
     $handler =& ProfileHandler_Array::getInstance(array('username' => $APIUsername, 'certificateFile' => null, 'subject' => null, 'environment' => $environment));
     $pid = ProfileHandler::generateID();
     $this->profile = new APIProfile($pid, $handler);
     $this->profile->setAPIUsername($APIUsername);
     $this->profile->setAPIPassword($APIPassword);
     $this->profile->setSignature($APISignature);
     //$this->profile->setCertificateFile($APICertificate);
     $this->profile->setEnvironment($environment);
 }