Esempio n. 1
0
 /** 
  * Constructor 
  * 
  * @param string $mode the mode of operation: live or test
  *
  * @return void 
  */
 function CRM_Utils_Payment_PayPal($mode)
 {
     require_once 'Services/PayPal.php';
     require_once 'Services/PayPal/Profile/Handler/File.php';
     require_once 'Services/PayPal/Profile/API.php';
     $config =& CRM_Core_Config::singleton();
     $this->_handler =& ProfileHandler_File::getInstance(array('path' => $config->paymentCertPath[$mode], 'charset' => CRM_UTILS_PAYMENT_PAYPAL_CHARSET));
     if (Services_PayPal::isError($handler)) {
         return CRM_Utils_Payment_PayPal::error($handler);
     }
     $this->_profile =& APIProfile::getInstance($config->paymentKey[$mode], $this->_handler);
     if (Services_PayPal::isError($this->_profile)) {
         return CRM_Utils_Payment_PayPal::error($this->_profile);
     }
     $this->_profile->setAPIPassword($config->paymentPassword[$mode]);
     $this->_caller =& Services_PayPal::getCallerServices($this->_profile);
     if (Services_PayPal::isError($this->_caller)) {
         $ret = CRM_Utils_Payment_PayPal::error($this->_caller);
         $this->_caller = null;
         return $ret;
     }
 }
 function paypal_init()
 {
     global $customer_id, $customer_first_name;
     $paypal_sdk_dir = 'Services/PayPal';
     require_once $paypal_sdk_dir . PHP;
     $paypal_sdk_dir .= '/Profile/';
     require_once $paypal_sdk_dir . 'Handler/Array.php';
     require_once $paypal_sdk_dir . 'API.php';
     $handler =& ProfileHandler_Array::getInstance(array('username' => MODULE_PAYMENT_PAYPAL_DP_API_USERNAME, 'certificateFile' => MODULE_PAYMENT_PAYPAL_DP_CERT_PATH, 'subject' => EMPTY_STRING, 'environment' => MODULE_PAYMENT_PAYPAL_DP_SERVER));
     $profile = APIProfile::getInstance(MODULE_PAYMENT_PAYPAL_DP_API_USERNAME, $handler);
     $profile->setAPIPassword(MODULE_PAYMENT_PAYPAL_DP_API_PASSWORD);
     $caller =& Services_PayPal::getCallerServices($profile);
     //Create a caller object.  Ring ring, who's there?
     if (!Services_PayPal::isError($caller)) {
         if (trim(MODULE_PAYMENT_PAYPAL_DP_PROXY) != EMPTY_STRING) {
             $caller->setOpt('curl', CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
             $caller->setOpt('curl', CURLOPT_PROXY, MODULE_PAYMENT_PAYPAL_DP_PROXY);
         }
         $caller->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0);
         $caller->setOpt('curl', CURLOPT_TIMEOUT, 180);
         $caller->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0);
     }
     if (Services_PayPal::isError($caller)) {
         if ($this->enableDebugging) {
             /*
             olc_php_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, $this->error_dump,
             "In Funktion: paypal_init()\n\n".var_dump($caller), STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
             */
             olc_php_mail(STORE_OWNER_EMAIL_ADDRESS, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, STORE_NAME, EMPTY_STRING, STORE_OWNER_EMAIL_ADDRESS, STORE_OWNER, EMPTY_STRING, EMPTY_STRING, $this->error_dump, EMPTY_STRING, str_replace(HASH, 'paypal_init', $this->in_function) . $this->prepare_var_dump($caller), EMAIL_TYPE_TEXT);
         }
         $error = $this->prepare_error(MODULE_PAYMENT_PAYPAL_DP_TEXT_GEN_ERROR, $caller);
         $this->away_with_you($error, true);
     } else {
         return $caller;
     }
 }
Esempio n. 3
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;
 }
<?php

// error_reporting(E_ALL);
header('Content-Type: text/plain');
require_once 'PayPal.php';
require_once 'PayPal/Profile/Handler/Array.php';
require_once 'PayPal/Profile/API.php';
require_once 'lib/constants.inc.php';
// Settings.
$certfile = dirname(__FILE__) . '/sdk-seller_cert_key_pem.txt';
$certpass = '';
$apiusername = '******';
$apipassword = '******';
$subject = null;
$environment = ENVIRONMENT;
$handler =& ProfileHandler_Array::getInstance(array('username' => $apiusername, 'certificateFile' => $certfile, 'subject' => $subject, 'environment' => $environment));
$profile =& APIProfile::getInstance($apiusername, $handler);
$profile->setAPIUsername($apiusername);
$profile->setAPIPassword($apipassword);
$profile->setCertificateFile($certfile);
$profile->setSignature(null);
$profile->setEnvironment($environment);
$caller =& PayPal::getCallerServices($profile);
if (PayPal::isError($caller)) {
    print "Could not create CallerServices instance: " . $caller->getMessage();
    exit;
}
Esempio n. 5
0
 function paypal_init()
 {
     global $customer_id, $customer_first_name;
     require_once 'Services/PayPal.php';
     require_once 'Services/PayPal/Profile/Handler/Array.php';
     require_once 'Services/PayPal/Profile/API.php';
     $handler =& ProfileHandler_Array::getInstance(array('username' => MODULE_PAYMENT_PAYPAL_DP_API_USERNAME, 'certificateFile' => MODULE_PAYMENT_PAYPAL_DP_CERT_PATH, 'subject' => '', 'environment' => MODULE_PAYMENT_PAYPAL_DP_SERVER));
     $profile = APIProfile::getInstance(MODULE_PAYMENT_PAYPAL_DP_API_USERNAME, $handler);
     $profile->setAPIPassword(MODULE_PAYMENT_PAYPAL_DP_API_PASSWORD);
     $caller =& Services_PayPal::getCallerServices($profile);
     //Create a caller object.  Ring ring, who's there?
     if (trim(MODULE_PAYMENT_PAYPAL_DP_PROXY) != '') {
         $caller->setOpt('curl', CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
         $caller->setOpt('curl', CURLOPT_PROXY, MODULE_PAYMENT_PAYPAL_DP_PROXY);
     }
     $caller->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0);
     $caller->setOpt('curl', CURLOPT_TIMEOUT, 180);
     $caller->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0);
     if (Services_PayPal::isError($caller)) {
         if ($this->enableDebugging == '1') {
             tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, 'PayPal Error Dump', "In function: paypal_init()\r\n\r\n" . var_dump($caller), STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
         }
         $this->away_with_you(MODULE_PAYMENT_PAYPAL_DP_TEXT_GEN_ERROR . $caller->Errors->ShortMessage . '<br>' . $caller->Errors->LongMessage . ' (' . $caller->Errors->ErrorCode . ')', true);
     } else {
         return $caller;
     }
 }
 /**
  * Get an instance of a caller
  *
  * @return bool
  */
 private function getCaller()
 {
     $handler =& ProfileHandler_Array::getInstance(array('username' => $this->api_username, 'certificateFile' => $this->api_certificate, 'signature' => $this->api_signature, 'subject' => $this->api_subject, 'environment' => $this->api_test ? 'Sandbox' : 'Live'));
     $profile =& APIProfile::getInstance($this->api_username, $handler);
     $profile->setAPIPassword($this->api_password);
     $this->api_caller =& PayPal::getCallerServices($profile);
     if (PayPal::isError($this->api_caller)) {
         $this->api_error_string = $this->api_caller->getMessage();
         return false;
     }
     return true;
 }
 /**
  * Creates a CallerServices object with our credentials
  * 
  * @throws RuntimeException if the API Caller could not be initialized
  * @return CallerServices
  */
 public function getCallerServices()
 {
     if ($this->_callerServices === null) {
         $username = $this->getUsername();
         $signature = $this->getSignature();
         $password = $this->getPassword();
         $environment = $this->isDebug() ? 'Sandbox' : 'Live';
         $handler = ProfileHandler_Array::getInstance(array('username' => $username, 'certificateFile' => null, 'signature' => $signature, 'subject' => null, 'environment' => $environment));
         $profile = APIProfile::getInstance($username, $handler);
         $profile->setAPIPassword($password);
         $caller = PayPal::getCallerServices($profile);
         if (PayPal::isError($caller)) {
             throw new RuntimeException('The API Caller could not be initialized: ' . $caller->getMessage());
         }
         // if we are in debug mode, ignore any invalid SSL certificates
         // TODO: Check if we also need this in production
         if ($this->isDebug()) {
             $caller->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0);
             $caller->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0);
         }
         $this->_callerServices = $caller;
     }
     return $this->_callerServices;
 }