public function getResponse($order = '') { if (empty($order)) { $order = $this->getOrder(); } $options = APP_Gateway_Registry::get_gateway_options('paypal'); return array('item_number' => $order->get_id(), 'mc_currency' => $order->get_currency(), 'mc_gross' => $order->get_total(), 'business' => $options['email_address']); }
/** * @depends test_register */ public function test_gateway_defaults($gateway) { $options = APP_Gateway_Registry::get_gateway_options($gateway->identifier()); $this->assertNotEmpty($options); $this->assertEquals($options['test_field'], 'test_value'); $real_options = APP_Gateway_Registry::get_options(); $real_options->gateways = array('enabled' => array(), $gateway->identifier() => array('test_field' => 'other_test_value')); $new_options = APP_Gateway_Registry::get_gateway_options($gateway->identifier()); $this->assertNotEmpty($new_options); $this->assertEquals('other_test_value', $new_options['test_field']); }
/** * Runs the process_recurring() method on a currently active gateway * @param string $gateway_id Identifier of currently active gateway * @param APP_Order $order Order to be processed * @return boolean False on error */ function appthemes_process_recurring_gateway($gateway_id, $order) { $receipt_order = APP_Order_Receipt::retrieve($order->get_id()); $options = APP_Gateway_Registry::get_gateway_options($gateway_id); $gateway = APP_Gateway_Registry::get_gateway($gateway_id); if (APP_Gateway_Registry::is_gateway_enabled($gateway_id) || current_user_can('manage_options')) { if (!$gateway->is_recurring()) { return false; } $gateway->process_recurring($receipt_order, $options); return true; } else { return false; } }
function pagseguro_create_payment_listener() { $code = isset($_POST['notificationCode']) && trim($_POST['notificationCode']) !== "" ? trim($_POST['notificationCode']) : null; $type = isset($_POST['notificationType']) && trim($_POST['notificationType']) !== "" ? trim($_POST['notificationType']) : null; if ($code && $type) { pagseguro_log('::::: Notificação PagSeguro recebida :::::'); $options = APP_Gateway_Registry::get_gateway_options('pagseguro'); $email = $options['user_email']; $token = $options['use_sandbox'] ? $options['user_token_sandbox'] : $options['user_token']; $url = $options['use_sandbox'] ? 'https://ws.sandbox.pagseguro.uol.com.br/v2/transactions/notifications/' : 'https://ws.pagseguro.uol.com.br/v2/transactions/notifications/'; $url = $url . $code . '?email=' . $email . '&token=' . $token; $ch = curl_init($url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $transaction = curl_exec($ch); if ($transaction == 'Unauthorized') { pagseguro_log('Transação não autorizada. Token: ' . $token); exit; } curl_close($ch); $transaction = simplexml_load_string($transaction); $status = $transaction->status; $order = APP_Order_Factory::retrieve(intval($transaction->reference)); if (false === $order) { pagseguro_log('ERRO: Não foi encontrado pedido com ID_TRANSACAO == ' . $transaction->reference); return; } switch ($status) { case 3: if ($order->get_status() == 'tr_activated') { pagseguro_log('Notificação repetida para ' . $transaction->reference . '. Ignorando...'); return; } $order->activate(); pagseguro_log('Pedido ' . $transaction->reference . ' foi ativado'); break; case 7: if ($order->get_status() == 'tr_failed') { pagseguro_log('Notificação repetida para ' . $transaction->reference . '. Ignorando...'); } $order->failed(); pagseguro_log('Pedido ' . $transaction->reference . ' foi cancelado'); } } }
/** * Checks that the order being given by PayPal matches the one on file * @return WP_Error Object containing errors, if any were found */ private function validate_order($order, $response, $errors = null) { $options = APP_Gateway_Registry::get_gateway_options('paypal'); if (!$errors) { $errors = new WP_Error(); } if (!isset($response['business']) || strtolower($options['email_address']) != strtolower($response['business'])) { $business = isset($response['business']) ? $response['business'] : 'no email given'; $errors->add('bad_email', 'Given email address did not match settings.' . $business . '/' . $options['email_address']); } if (!isset($response['mc_currency']) || $order->get_currency() != strtoupper($response['mc_currency'])) { $errors->add('bad_currency', 'Given currency code did not match order.'); } if ($order->get_gateway() != 'paypal') { $errors->add('bad_gateway', 'Order was not using PayPal as a gateway.'); } return $errors; }
/** * Retrieves details for an escrow order. * * @param APP_Escrow_Order $order The order object * * @return bool|mixed The details for the order or False if no details found */ function appthemes_get_escrow_details(APP_Escrow_Order $order) { $gateway_id = $order->get_gateway(); $gateway = APP_Gateway_Registry::get_gateway($gateway_id); if ($gateway && (APP_Gateway_Registry::is_gateway_enabled($gateway_id) || current_user_can('manage_options'))) { if (!$gateway instanceof APP_Escrow_Payment_Processor) { return false; } $options = APP_Gateway_Registry::get_gateway_options($gateway_id); return $gateway->get_details($order, $options); } else { return false; } }
function is_recurring() { $options = APP_Gateway_Registry::get_gateway_options('paypal'); return !empty($options['business_account']); }
/** * Verify that the defaults are returned for gateway * @depends test_gateway_creation */ public function test_form_return($gateway) { $form = $gateway->form(); $values = APP_Gateway_Registry::get_gateway_options($gateway->identifier()); $this->assertNotEmpty($values); foreach ($form['fields'] as $field) { $this->assertEquals($values[$field['name']], $field['default']); } }
function appthemes_process_gateway($gateway_id, $order) { $options = APP_Gateway_Registry::get_gateway_options($gateway_id); $gateway = APP_Gateway_Registry::get_gateway($gateway_id); $gateway->process($order, $options); }