/** * Constructor * * @access public * @param array config preferences * @return void */ function __construct($DataArray) { parent::__construct($DataArray); $this->XMLNamespace = 'http://svcs.paypal.com/types/ap'; $this->DeviceID = isset($DataArray['DeviceID']) ? $DataArray['DeviceID'] : ''; $this->IPAddress = isset($DataArray['IPAddress']) ? $DataArray['IPAddress'] : $_SERVER['REMOTE_ADDR']; $this->DetailLevel = isset($DataArray['DetailLevel']) ? $DataArray['DetailLevel'] : 'ReturnAll'; $this->ErrorLanguage = isset($DataArray['ErrorLanguage']) ? $DataArray['ErrorLanguage'] : 'en_US'; $this->APISubject = isset($DataArray['APISubject']) ? $DataArray['APISubject'] : ''; $this->DeveloperAccountEmail = isset($DataArray['DeveloperAccountEmail']) ? $DataArray['DeveloperAccountEmail'] : ''; if ($this->Sandbox) { // Sandbox Credentials $this->ApplicationID = isset($DataArray['ApplicationID']) ? $DataArray['ApplicationID'] : ''; $this->APIUsername = isset($DataArray['APIUsername']) && $DataArray['APIUsername'] != '' ? $DataArray['APIUsername'] : ''; $this->APIPassword = isset($DataArray['APIPassword']) && $DataArray['APIPassword'] != '' ? $DataArray['APIPassword'] : ''; $this->APISignature = isset($DataArray['APISignature']) && $DataArray['APISignature'] != '' ? $DataArray['APISignature'] : ''; $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != '' ? $DataArray['EndPointURL'] : 'https://svcs.sandbox.paypal.com/'; } elseif ($this->BetaSandbox) { // Beta Sandbox Credentials $this->ApplicationID = isset($DataArray['ApplicationID']) ? $DataArray['ApplicationID'] : ''; $this->APIUsername = isset($DataArray['APIUsername']) && $DataArray['APIUsername'] != '' ? $DataArray['APIUsername'] : ''; $this->APIPassword = isset($DataArray['APIPassword']) && $DataArray['APIPassword'] != '' ? $DataArray['APIPassword'] : ''; $this->APISignature = isset($DataArray['APISignature']) && $DataArray['APISignature'] != '' ? $DataArray['APISignature'] : ''; $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != '' ? $DataArray['EndPointURL'] : 'https://svcs.beta-sandbox.paypal.com/'; } else { // Live Credentials $this->ApplicationID = isset($DataArray['ApplicationID']) ? $DataArray['ApplicationID'] : ''; $this->APIUsername = isset($DataArray['APIUsername']) && $DataArray['APIUsername'] != '' ? $DataArray['APIUsername'] : ''; $this->APIPassword = isset($DataArray['APIPassword']) && $DataArray['APIPassword'] != '' ? $DataArray['APIPassword'] : ''; $this->APISignature = isset($DataArray['APISignature']) && $DataArray['APISignature'] != '' ? $DataArray['APISignature'] : ''; $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != '' ? $DataArray['EndPointURL'] : 'https://svcs.paypal.com/'; } }
/** * Constructor * * @access public * @param array config preferences * @return void */ function __construct($DataArray) { parent::__construct($DataArray); $this->AccessKey = isset($DataArray['AccessKey']) ? $DataArray['AccessKey'] : ''; $this->ClientSecret = isset($DataArray['ClientSecret']) && $DataArray['ClientSecret'] != '' ? $DataArray['ClientSecret'] : ''; if ($this->Sandbox) { $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != '' ? $DataArray['EndPointURL'] : 'https://api.financing-mint.paypal.com/finapi/v1/publishers/'; } else { $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != '' ? $DataArray['EndPointURL'] : 'https://api.financing.paypal.com/finapi/v1/publishers/'; } }
/** * Constructor * * @access public * @param array config preferences * @return void */ function __construct($DataArray) { parent::__construct($DataArray); $this->APIVendor = isset($DataArray['APIVendor']) ? $DataArray['APIVendor'] : ''; $this->APIPartner = isset($DataArray['APIPartner']) ? $DataArray['APIPartner'] : ''; $this->Verbosity = isset($DataArray['Verbosity']) ? $DataArray['Verbosity'] : 'HIGH'; if ($this->Sandbox) { $this->APIEndPoint = 'https://pilot-payflowpro.paypal.com'; } else { $this->APIEndPoint = 'https://payflowpro.paypal.com'; } $this->NVPCredentials = 'BUTTONSOURCE[' . strlen($this->APIButtonSource) . ']=' . $this->APIButtonSource . '&VERBOSITY[' . strlen($this->Verbosity) . ']=' . $this->Verbosity . '&USER[' . strlen($this->APIUsername) . ']=' . $this->APIUsername . '&VENDOR[' . strlen($this->APIVendor) . ']=' . $this->APIVendor . '&PARTNER[' . strlen($this->APIPartner) . ']=' . $this->APIPartner . '&PWD[' . strlen($this->APIPassword) . ']=' . $this->APIPassword; $this->TransactionStateCodes = array('1' => 'Error', '6' => 'Settlement Pending', '7' => 'Settlement in Progress', '8' => 'Settlement Completed Successfully', '11' => 'Settlement Failed', '14' => 'Settlement Incomplete'); }
/** * Process a refund if supported * @param int $order_id * @param float $amount * @param string $reason * @return bool|wp_error True or false based on success, or a WP_Error object */ public function process_refund($order_id, $amount = null, $reason = '') { $order = wc_get_order($order_id); $this->add_log('Begin Refund'); $this->add_log('Order: ' . print_r($order, true)); $this->add_log('Transaction ID: ' . print_r($order->get_transaction_id(), true)); $this->add_log('API Username: '******'API Password: '******'API Signature: ' . print_r($this->api_signature, true)); if (!$order || !$order->get_transaction_id() || !$this->api_username || !$this->api_password || !$this->api_signature) { return false; } $this->add_log('Include Class Request'); /* * Check if the PayPal class has already been established. */ if (!class_exists('Angelleye_PayPal')) { require_once 'lib/angelleye/paypal-php-library/includes/paypal.class.php'; } /* * Create PayPal object. */ $PayPalConfig = array('Sandbox' => $this->testmode == 'yes' ? TRUE : FALSE, 'APIUsername' => $this->api_username, 'APIPassword' => $this->api_password, 'APISignature' => $this->api_signature); $PayPal = new Angelleye_PayPal($PayPalConfig); if ($reason) { if (255 < strlen($reason)) { $reason = substr($reason, 0, 252) . '...'; } $reason = html_entity_decode($reason, ENT_NOQUOTES, 'UTF-8'); } // Prepare request arrays $RTFields = array('transactionid' => $order->get_transaction_id(), 'payerid' => '', 'invoiceid' => '', 'refundtype' => $order->get_total() == $amount ? 'Full' : 'Partial', 'amt' => number_format($amount, 2, '.', ''), 'currencycode' => $order->get_order_currency(), 'note' => $reason, 'retryuntil' => '', 'refundsource' => '', 'merchantstoredetail' => '', 'refundadvice' => '', 'refunditemdetails' => '', 'msgsubid' => '', 'storeid' => '', 'terminalid' => ''); $PayPalRequestData = array('RTFields' => $RTFields); $this->add_log('Refund Request: ' . print_r($PayPalRequestData, true)); // Pass data into class for processing with PayPal and load the response array into $PayPalResult $PayPalResult = $PayPal->RefundTransaction($PayPalRequestData); $this->add_log('Refund Information: ' . print_r($PayPalResult, true)); if ($PayPal->APICallSuccessful($PayPalResult['ACK'])) { $order->add_order_note('Refund Transaction ID:' . $PayPalResult['REFUNDTRANSACTIONID']); $max_remaining_refund = wc_format_decimal($order->get_total() - $order->get_total_refunded()); if (!$max_remaining_refund > 0) { $order->update_status('refunded'); } if (ob_get_length()) { ob_end_clean(); } return true; } else { $pc_message = apply_filters('angelleye_pc_refund_message', $PayPalResult['L_LONGMESSAGE0'], $PayPalResult['L_ERRORCODE'], $PayPalResult); return new WP_Error('ec_refund-error', $pc_message); } }
* This is a bare-bones template for building a callback listener for PayPal Express Checkout. * If you include the CALLBACK parameters in your SetExpressCheckout request, this is what you * you would setup as your callback URL. PayPal will hit your callback URL with address and item details * from the Express Checkout review page in order to populate their screen with shipping and sales tax * information that you pass back from this service. * * This allows you to build real-time shipping and tax calculations into Express Checkout * so that you won't need to display another review page on your own site. */ error_reporting(E_ALL); ini_set('display_errors', '1'); require_once '../includes/config.php'; require_once 'paypal.class.php'; // Configure PayPal object $paypal_config = array('Sandbox' => $sandbox); $paypal = new Angelleye_PayPal($paypal_config); // Receive data from PayPal and load varaibles accordingly. $method = isset($_POST['METHOD']) ? $_POST['METHOD'] : ''; $token = isset($_POST['TOKEN']) ? $_POST['TOKEN'] : ''; $currency_code = isset($_POST['CURRENCYCODE']) ? $_POST['CURRENCYCODE'] : ''; $local_code = isset($_POST['LOCALECODE']) ? $_POST['LOCALECODE'] : ''; $order_items = $paypal->GetOrderItems($_POST); $shipping_street = isset($_POST['SHIPTOSTREET']) ? $_POST['SHIPTOSTREET'] : ''; $shipping_street2 = isset($_POST['SHIPTOSTREET2']) ? $_POST['SHIPTOSTREET2'] : ''; $shipping_city = isset($_POST['SHIPTOCITY']) ? $_POST['SHIPTOCITY'] : ''; $shipping_state = isset($_POST['SHIPTOSTATE']) ? $_POST['SHIPTOSTATE'] : ''; $shipping_zip = isset($_POST['SHIPTOZIP']) ? $_POST['SHIPTOZIP'] : ''; $shipping_country_code = isset($_POST['SHIPTOCOUNTRY']) ? $_POST['SHIPTOCOUNTRY'] : ''; // Here, we may setup static shipping and tax options, or we could hit a 3rd party // web service API (eg. UPS, FedEx, USPS) to gather rates in real-time. //