/** * Displays the form for user redirection * @param APP_Order $order Order to process * @param array $options User inputted options * @return void */ public static function create_form($order, $options, $return_url, $cancel_url) { $options = wp_parse_args($options, array('email_address' => '')); $fields = array(self::SELLER_EMAIL => $options['email_address'], self::ITEM_NAME => $order->get_description(), self::ITEM_NUMBER => $order->get_id(), self::CURRENCY_CODE => $order->get_currency(), self::RETURN_TEXT => sprintf(__('Continue to %s', APP_TD), get_bloginfo('name')), self::RETURN_URL => $return_url, self::CANCEL_URL => $cancel_url, self::NO_SHIPPING => 1, self::NO_NOTE => 1, self::RETURN_METHOD => self::RETURN_BY_GET, self::CHARSET => 'utf-8'); if ($order->is_recurring()) { if (get_post_meta($order->get_id(), 'paypal_subscription_id', true)) { self::print_processing_script($order); return array(); } $fields[self::TYPE] = self::SUBSCRIBE; $fields[self::RECURR_BILLING] = 1; $subscription_id = $order->get_id() . mt_rand(0, 1000); $fields[self::INVOICE] = $subscription_id; update_post_meta($order->get_id(), 'paypal_subscription_id', $subscription_id); $fields[self::RECURRING_AMOUNT] = $order->get_total(); $recurring_period_info = self::get_recurring_period_info($order->get_recurring_period(), $order->get_recurring_period_type()); $fields[self::RECURRING_PERIOD] = $recurring_period_info['recurring_period']; $fields[self::RECURRING_PERIOD_TYPE] = $recurring_period_info['recurring_period_type']; } else { $fields[self::TYPE] = self::BUY_NOW; $fields[self::AMOUNT] = $order->get_total(); } if (!empty($options['ipn_enabled'])) { $fields[self::NOTIFY_URL] = APP_PayPal_IPN_Listener::get_listener_url(); } $form = array('action' => APP_PayPal::get_request_url(), 'name' => 'paypal_payform', 'id' => 'create_listing'); return array($form, $fields); }
public function validate_request() { $paypal_url = APP_PayPal::get_request_url(); $received_values = array('cmd' => '_notify-validate'); $received_values += stripslashes_deep($_POST); $params = array('body' => $received_values, 'sslverify' => false, 'timeout' => 60, 'httpversion' => '1.1', 'user-agent' => 'AppThemes/' . get_bloginfo('version')); $response = wp_remote_post($paypal_url, $params); if (is_wp_error($response)) { return false; } if ($response['response']['code'] >= 200 && $response['response']['code'] < 300) { if (preg_match("/VERIFIED/s", $response['body'])) { return true; } } return false; }
/** * See process_escrow() */ protected function _process_escrow(APP_Escrow_Order $order, $options) { $return_url = $this->get_return_url($order); $cancel_url = $this->get_cancel_url($order); $pp_adaptive_request = new APP_PayPal_Adaptive_Request($options); $pay_response = $pp_adaptive_request->pay($order, $return_url, $cancel_url); $responsecode = strtoupper($pay_response['responseEnvelope']['ack']); if ('SUCCESS' != $responsecode && 'SUCCESSWITHWARNING' != $responsecode) { $this->fail_order(__('PayPal was not able to execute the payment request. Please contact site owner.', APP_TD)); if ($responsecode) { $order->log(sprintf(__('The following error ocurred while trying to make the pay request: "%s"', APP_TD), $pay_response['error'][0]['message'])); } else { $order->log(__('No response code from PayPal while trying to execute the payment.', APP_TD)); } return false; } $order->add_data('pay_key', $pay_response['payKey']); $form_atts = array('name' => 'paypal_payform', 'action' => APP_PayPal::get_request_url()); $fields = array('cmd' => '_ap-payment', 'paykey' => $pay_response['payKey']); $this->redirect($form_atts, $fields, __('You are now being redirected to PayPal.', APP_TD)); return true; }
/** * Checks whether the current response is a valid transaction key * @param APP_Order $order Order being processed * @param array $options User inputted options * @return boolean True if transaction key is valid, false if invalid */ public static function get_transaction($transaction_key, $identity_token, $sandbox = false) { $data = array('cmd' => '_notify-synch', 'tx' => $transaction_key, 'at' => $identity_token); $url = APP_PayPal::get_request_url(); $options = array('method' => 'POST', 'body' => $data, 'sslverify' => false, 'httpversion' => '1.1'); $response = self::get_url($url, $options); if (strpos($response, 'SUCCESS') !== 0) { return false; } $values = array(); $lines = explode("\n", $response); foreach ($lines as $string) { $key_value_string = explode('=', $string); if (array_key_exists(1, $key_value_string)) { $value = $key_value_string[1]; } else { $value = ''; } $values[$key_value_string[0]] = urldecode($value); } return $values; wp_update_post(array("ID" => $order->get_id(), "post_content" => $transaction_id)); }