Ejemplo n.º 1
0
 function deleteProfile($id)
 {
     $retval = $this->validateParams();
     if (PayPal::isError($retval)) {
         return $retval;
     }
     $delete_file = $this->_getFileName($id);
     if (!@unlink($delete_file)) {
         return PayPal::raiseError("Could not delete the Profile file '{$delete_file}'");
     }
     return true;
 }
Ejemplo n.º 2
0
 public function sendDirectPaymentRequest($authorization = true, array $options = null)
 {
     if ($options != null) {
         $this->setOptions($options);
     }
     $this->buildDirectPaymentRequest($authorization);
     $caller =& PayPal::getCallerServices($this->profile);
     $isError = true;
     if (method_exists($caller, 'DoDirectPayment')) {
         $response = $caller->DoDirectPayment($this->request);
         $isError = PayPal::isError($response);
         $this->buildErrors($response);
     }
     if (!$isError && $response->getAck() == 'Success') {
         $this->transactionID = $response->TransactionID;
         return true;
     } else {
         $this->transactionID = -1;
         return false;
     }
 }
Ejemplo n.º 3
0
$was_submitted = false;
$logger = new SampleLogger('CaptureReceipt.php', PEAR_LOG_DEBUG);
$logger->_log('POST variables: ' . print_r($_POST, true));
$profile = $_SESSION['APIProfile'];
// Verify that user is logged in
if (!isset($profile)) {
    // Not logged in -- Back to the login page
    $logger->_log('You are not logged in;  return to index.php');
    $location = 'index.php';
    header("Location: {$location}");
} else {
    $logger->_log('Profile from session: ' . print_r($profile, true));
}
// Build our request from $_POST
$capture_request =& PayPal::getType('DoCaptureRequestType');
if (PayPal::isError($capture_request)) {
    $logger->_log('Error in request: ' . $capture_request);
} else {
    $logger->_log('Create request: ' . $capture_request);
}
// Set request fields
$authorization_id = $_POST['authorization_id'];
if (isset($authorization_id)) {
    $capture_request->setAuthorizationID($authorization_id, 'iso-8859-1');
}
$complete_code_type = $_POST['CompleteCodeType'];
$capture_request->setCompleteType($complete_code_type);
$invoice_id = $_POST['invoice_id'];
if (isset($invoice_id)) {
    $capture_request->setInvoiceID($invoice_id);
}
Ejemplo n.º 4
0
 /**
  * Factory for creating instances of the EWPProfile. Used when
  * providing an existing Profile ID to load from
  *
  * @param string The Profile ID of this instance
  * @param object A valid Profile Handler instance
  * @return object A new instance of EWPProfile for the given ID or a PayPal error object on failure
  */
 function getInstance($id, &$handler)
 {
     $classname = __CLASS__;
     $inst = new $classname($id, $handler);
     $result = $inst->_load();
     if (PayPal::isError($result)) {
         return $result;
     }
     return $inst;
 }
Ejemplo n.º 5
0
 /**
  * Returns an array of valid Environments
  *
  * @return array An array of valid environment names
  */
 function getValidEnvironments()
 {
     if (empty($this->_validEnvironments)) {
         $res = $this->loadEnvironments();
         if (PayPal::isError($res)) {
             return $res;
         }
     }
     return $this->_validEnvironments;
 }
Ejemplo n.º 6
0
$was_submitted = false;
$logger = new SampleLogger('VoidReceipt.php', PEAR_LOG_DEBUG);
$logger->_log('POST variables: ' . print_r($_POST, true));
$profile = $_SESSION['APIProfile'];
// Verify that user is logged in
if (!isset($profile)) {
    // Not logged in -- Back to the login page
    $logger->_log('You are not logged in;  return to index.php');
    $location = 'index.php';
    header("Location: {$location}");
} else {
    $logger->_log('Profile from session: ' . print_r($profile, true));
}
// Build our request from $_POST
$void_request =& PayPal::getType('DoVoidRequestType');
if (PayPal::isError($void_request)) {
    $logger->_log('Error in request: ' . print_r($void_request, true));
} else {
    $logger->_log('Create request: ' . print_r($void_request, true));
}
// Set request fields
$authorization_id = $_POST['authorization_id'];
if (isset($authorization_id)) {
    $void_request->setAuthorizationID($authorization_id, 'iso-8859-1');
}
$note = $_POST['note'];
if (isset($note)) {
    $void_request->setNote($note);
}
$logger->_log('Initial request: ' . print_r($void_request, true));
$caller =& PayPal::getCallerServices($profile);
 /**
  * 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;
 }
Ejemplo n.º 8
0
$was_submitted = false;
$logger = new SampleLogger('RefundReceipt.php', PEAR_LOG_DEBUG);
$logger->_log('POST variables: ' . print_r($_POST, true));
$profile = $_SESSION['APIProfile'];
// Verify that user is logged in
if (!isset($profile)) {
    // Not logged in -- Back to the login page
    $logger->_log('You are not logged in;  return to index.php');
    $location = 'index.php';
    header("Location: {$location}");
} else {
    $logger->_log('Profile from session: ' . print_r($profile, true));
}
// Build our request from $_POST
$refund_request =& PayPal::getType('RefundTransactionRequestType');
if (PayPal::isError($refund_request)) {
    $logger->_log('Error in request: ' . print_r($refund_request, true));
} else {
    $logger->_log('Create request: ' . print_r($refund_request, true));
}
// Transaction ID is required
$tran_id = $_POST['transactionID'];
if (isset($tran_id)) {
    $refund_request->setTransactionId($tran_id, 'iso-8859-1');
} else {
    // Error: transaction ID is required
    $location = 'RefundTransaction.php';
    header("Location: {$location}");
}
// refundType is optional and must be translated
// amount is optional
$logger = new SampleLogger('TransactionDetails.php', PEAR_LOG_DEBUG);
$logger->_log('POST variables: ' . print_r($_POST, true));
$profile = $_SESSION['APIProfile'];
// Verify that user is logged in
if (!isset($profile)) {
    // Not logged in -- Back to the login page
    $logger->_log('You are not logged in;  return to index.php');
    header("Location: index.php");
    exit;
} else {
    $logger->_log('Profile from session: ' . print_r($profile, true));
}
// Build our request from $_POST
// $trans_details = new TransactionSearchRequestType();
$trans_details =& PayPal::getType('GetTransactionDetailsRequestType');
if (PayPal::isError($trans_details)) {
    $logger->_log('Error in request: ' . print_r($trans_details, true));
} else {
    $logger->_log('Create request: ' . print_r($trans_details, true));
}
// Set request fields
$tran_id = $_GET['transactionID'];
if (isset($tran_id)) {
    $trans_details->setTransactionId($tran_id, 'iso-8859-1');
} else {
    // Error: transaction ID was not set
    $location = 'GetTransactionDetails.php';
    header("Location: {$location}");
    exit;
}
$logger->_log('Initial request: ' . print_r($trans_details, true));
$logger = new SampleLogger('GetRPProfileDetails.php', PEAR_LOG_DEBUG);
$logger->_log('POST variables: ' . print_r($_POST, true));
$profile = $_SESSION['APIProfile'];
// $caller = $_SESSION['caller'];
// Verify that user is logged in
if (!isset($profile)) {
    // Not logged in -- Back to the login page
    $logger->_log('You are not logged in;  return to index.php');
    $location = '../index.php';
    header("Location: {$location}");
} else {
    $logger->_log('Profile from session: ' . print_r($profile, true));
}
// Build our request from $_POST
$grppd_request =& PayPal::getType('GetRecurringPaymentsProfileDetailsRequestType');
if (PayPal::isError($crpp_request)) {
    $logger->_log('Error in request: ' . print_r($grppd_request, true));
} else {
    $logger->_log('Create request: ' . print_r($grppd_request, true));
}
$logger->_log('Initial request: ' . print_r($grppd_request, true));
/**
 * Get posted request values
 */
$profileID = $_POST['profileID'];
$grppd_request->setProfileID($profileID);
$caller =& PayPal::getCallerServices($profile);
// Execute SOAP request
$response = $caller->GetRecurringPaymentsProfileDetails($grppd_request);
$ack = $response->getAck();
$logger->_log('Ack=' . $ack);
Ejemplo n.º 11
0
<?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;
}
$was_submitted = false;
$logger = new SampleLogger('AuthorizationReceipt.php', PEAR_LOG_DEBUG);
$logger->_log('POST variables: ' . print_r($_POST, true));
$profile = $_SESSION['APIProfile'];
// Verify that user is logged in
if (!isset($profile)) {
    // Not logged in -- Back to the login page
    $logger->_log('You are not logged in;  return to index.php');
    $location = 'index.php';
    header("Location: {$location}");
} else {
    $logger->_log('Profile from session: ' . print_r($profile, true));
}
// Build our request from $_POST
$authorization_request =& PayPal::getType('DoAuthorizationRequestType');
if (PayPal::isError($authorization_request)) {
    $logger->_log('Error in request: ' . print_r($authorization_request, true));
}
// Set request fields
$authorization_request->setTransactionID($_POST['order_id']);
$authorization_request->setTransactionEntity('Order');
$amtType =& PayPal::getType('BasicAmountType');
$amtType->setattr('currencyID', $_POST['currency']);
$amtType->setval($_POST['amount'], 'iso-8859-1');
$authorization_request->setAmount($amtType);
$logger->_log('Initial request: ' . print_r($authorization_request, true));
$caller =& PayPal::getCallerServices($profile);
$response = $caller->DoAuthorization($authorization_request);
$ack = $response->getAck();
$logger->_log('Ack=' . $ack);
switch ($ack) {
$creditCardNumber = $_POST['creditCardNumber'];
$expDateMonth = $_POST['expDateMonth'];
// Month must be padded with leading zero
$padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT);
$expDateYear = $_POST['expDateYear'];
$cvv2Number = $_POST['cvv2Number'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$amount = $_POST['amount'];
// Populate SOAP request information
// Payment details
$OrderTotal =& PayPal::getType('BasicAmountType');
if (PayPal::isError($OrderTotal)) {
    var_dump($OrderTotal);
    exit;
}
$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);
Ejemplo n.º 14
0
$was_submitted = false;
$logger = new SampleLogger('MassPayReceipt.php', PEAR_LOG_DEBUG);
$logger->_log('POST variables: ' . print_r($_POST, true));
$profile = $_SESSION['APIProfile'];
// Verify that user is logged in
if (!isset($profile)) {
    // Not logged in -- Back to the login page
    $logger->_log('You are not logged in;  return to index.php');
    $location = 'index.php';
    header("Location: {$location}");
} else {
    $logger->_log('Profile from session: ' . print_r($profile, true));
}
// Build our request from $_POST
$masspay_request =& PayPal::getType('MassPayRequestType');
if (PayPal::isError($masspay_request)) {
    $logger->_log('Error in request: ' . print_r($masspay_request, true));
} else {
    $logger->_log('Create request: ' . print_r($masspay_request, true));
}
// Set request fields
$emailSubject = $_POST['emailSubject'];
$receiverType = $_POST['receiverType'];
for ($i = 0, $j = 0; $i < count($_POST["receiveremail"]); $i++) {
    if (isset($_POST['receiveremail'][$i]) && $_POST['receiveremail'][$i] != '') {
        $massPayItems[$j] =& PayPal::getType('MassPayRequestItemType');
        $massPayItems[$j]->setReceiverEmail($_POST["receiveremail"][$i]);
        $massPayItems[$j]->setNote($_POST["note"][$i]);
        $massPayItems[$j]->setUniqueId($_POST["uniqueID"][$i]);
        $amtType =& PayPal::getType('BasicAmountType');
        $amtType->setattr('currencyID', 'USD');
session_start();
set_time_limit(60);
$was_submitted = false;
$logger = new SampleLogger('TransactionSearchResults.php', PEAR_LOG_DEBUG);
$logger->_log('POST variables: ' . print_r($_POST, true));
$profile = $_SESSION['APIProfile'];
// Verify that user is logged in
if (!isset($profile)) {
    // Not logged in -- Back to the login page
    $logger->_log('You are not logged in;  return to index.php');
    $location = 'index.php';
    header("Location: {$location}");
}
// Build our request from $_POST
$trans_search =& PayPal::getType('TransactionSearchRequestType');
if (PayPal::isError($trans_search)) {
    $logger->_log('Error in request: ' . $trans_search);
} else {
    $logger->_log('Create request: ' . $trans_search);
}
// Set request fields
$start_date_str = $_POST['startDateStr'];
if (isset($start_date_str)) {
    $start_time = strtotime($start_date_str);
    $iso_start = date('Y-m-d\\T00:00:00\\Z', $start_time);
    $trans_search->setStartDate($iso_start, 'iso-8859-1');
}
$end_date_str = $_POST['endDateStr'];
if (isset($end_date_str)) {
    $end_time = strtotime($end_date_str);
    $iso_end = date('Y-m-d\\T24:00:00\\Z', $end_time);
Ejemplo n.º 16
0
 /**
  * Load an EWPServices object for performing encryption
  * operations.
  *
  * @param EWPProfile $profile  The profile with the username, password,
  *                             and any other information necessary to use
  *                             EWPServices.
  *
  * @return EWPServices  A PayPal EWP services object.
  *
  * @static
  */
 function &getEWPServices($profile)
 {
     if (!is_a($profile, 'EWPProfile')) {
         return parent::raiseError("You must provide a valid EWPProfile");
     }
     $result = $profile->validate();
     if (PayPal::isError($result)) {
         return $result;
     }
     include_once 'PayPal/EWPServices.php';
     return $c = new EWPServices($profile);
 }
Ejemplo n.º 17
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;
 }
Ejemplo n.º 18
0
 function &DoAuthorization($DoAuthorizationReq)
 {
     $start = $this->_getMicroseconds();
     // Handle type objects.
     if (is_a($DoAuthorizationReq, 'XSDType')) {
         $DoAuthorizationReq->setVersion(PAYPAL_WSDL_VERSION);
         $DoAuthorizationReq = $DoAuthorizationReq->getSoapValue('DoAuthorizationRequest', 'urn:ebay:api:PayPalAPI');
     }
     // Make sure we can find a valid WSDL endpoint for this method.
     $res = $this->setEndpoint('PayPalAPIAA', PAYPAL_WSDL_VERSION);
     if (PayPal::isError($res)) {
         $this->_logTransaction('DoAuthorization', $this->_getElapsed($start), $res);
         return $res;
     }
     // DoAuthorizationReq is a ComplexType, refer to the WSDL for more info.
     $DoAuthorizationReq_attr['xmlns'] = 'urn:ebay:api:PayPalAPI';
     $DoAuthorizationReq =& new SOAP_Value('DoAuthorizationReq', false, $DoAuthorizationReq, $DoAuthorizationReq_attr);
     $result = $this->call('DoAuthorization', $v = array("DoAuthorizationReq" => $DoAuthorizationReq), array('namespace' => 'urn:ebay:api:PayPalAPI', 'soapaction' => '', 'style' => 'document', 'use' => 'literal'));
     $response = $this->getResponseObject($result, 'DoAuthorizationResponseType');
     $this->_logTransaction('DoAuthorization', $this->_getElapsed($start), $response);
     return $response;
 }
$was_submitted = false;
$logger = new SampleLogger('GetBalanceRecipt.php', PEAR_LOG_DEBUG);
$logger->_log('POST variables: ' . print_r($_POST, true));
$profile = $_SESSION['APIProfile'];
// Verify that user is logged in
if (!isset($profile)) {
    // Not logged in -- Back to the login page
    $logger->_log('You are not logged in;  return to index.php');
    $location = 'index.php';
    header("Location: {$location}");
} else {
    $logger->_log('Profile from session: ' . print_r($profile, true));
}
// Build our request from $_POST
$getbalance_request =& PayPal::getType('GetBalanceRequestType');
if (PayPal::isError($getbalance_request)) {
    $logger->_log('Error in request: ' . print_r($getbalance_request, true));
} else {
    $logger->_log('Create request: ' . print_r($getbalance_request, true));
}
$logger->_log('Initial request: ' . print_r($getbalance_request, true));
$caller =& PayPal::getCallerServices($profile);
$response = $caller->GetBalance($getbalance_request);
$ack = $response->getAck();
$logger->_log('Ack=' . $ack);
switch ($ack) {
    case ACK_SUCCESS:
    case ACK_SUCCESS_WITH_WARNING:
        // Good to break out;
        break;
    default:
Ejemplo n.º 20
0
    /**
     * Creates a new encrypted button HTML block
     *
     * @param array The button parameters as key/value pairs
     * @return mixed A string of HTML or a Paypal error object on failure
     */
    function encryptButton($buttonParams)
    {
        if (!is_object($this->_profile)) {
            return PayPal::raiseError("No Profile is set, cannot encrypt");
        }
        $res = $this->_profile->validate();
        if (PayPal::isError($res)) {
            return $res;
        }
        $merchant_cert = 'file://' . $this->_profile->getCertificateFile();
        $merchant_key = 'file://' . $this->_profile->getPrivateKeyFile();
        $enc_cert = 'file://' . $this->getPayPalCertificateFile($this->_profile->getEnvironment());
        $tmpin_file = tempnam('/tmp', 'paypal_');
        $tmpout_file = tempnam('/tmp', 'paypal_');
        $tmpfinal_file = tempnam('/tmp', 'paypal_');
        $rawdata = array();
        $buttonParams['cert_id'] = $this->_profile->getCertificateId();
        foreach ($buttonParams as $name => $value) {
            $rawdata[] = "{$name}={$value}";
        }
        $rawdata = implode("\n", $rawdata);
        $fp = fopen($tmpin_file, 'w');
        if (!$fp) {
            return PayPal::raiseError("Could not open temporary file '{$tmpin_file}')");
        }
        fwrite($fp, $rawdata);
        fclose($fp);
        if (!@openssl_pkcs7_sign($tmpin_file, $tmpout_file, $merchant_cert, array($merchant_key, $this->_profile->getPrivateKeyPassword()), array(), PKCS7_BINARY)) {
            return PayPal::raiseError("Could not sign encrypted data: " . openssl_error_string());
        }
        $data = file_get_contents($tmpout_file);
        $data = explode("\n\n", $data);
        $data = $data[1];
        $data = base64_decode($data);
        $fp = fopen($tmpout_file, 'w');
        if (!$fp) {
            return PayPal::raiseError("Could not open temporary file '{$tmpin_file}')");
        }
        fwrite($fp, $data);
        fclose($fp);
        if (!@openssl_pkcs7_encrypt($tmpout_file, $tmpfinal_file, $enc_cert, array(), PKCS7_BINARY)) {
            return PayPal::raiseError("Could not encrypt data:" . openssl_error_string());
        }
        $encdata = @file_get_contents($tmpfinal_file, false);
        if (!$encdata) {
            return PayPal::raiseError("Encryption and signature of data failed.");
        }
        $encdata = explode("\n\n", $encdata);
        $encdata = trim(str_replace("\n", '', $encdata[1]));
        $encdata = "-----BEGIN PKCS7-----{$encdata}-----END PKCS7-----";
        @unlink($tmpfinal_file);
        @unlink($tmpin_file);
        @unlink($tmpout_file);
        $action = $this->_profile->getUrl();
        $buttonimgurl = $this->_profile->getButtonImage();
        $retval = <<<PPHTML
<FORM ACTION="{$action}" METHOD="post">
<INPUT TYPE="hidden" NAME="cmd" VALUE="_s-xclick">
<INPUT TYPE="hidden" NAME="encrypted" VALUE="{$encdata}">
<INPUT TYPE="image" SRC="{$buttonimgurl}" BORDER="0" NAME="submit" ALT="Make Payments with PayPal -- it's fast, free and secure!">
</FORM>
PPHTML;
        return $retval;
    }
 /**
  * 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;
 }