Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function _wpec_get_checkout_token( $product, $return_url ) {
- global $wpdb, $wpsc_cart, $current_user;
- wpsc_empty_cart();
- // Manually add the product to the WPEC cart
- $_POST['product_id'] = $product->get_id();
- $_POST['collected_data'] = false;
- wpsc_add_to_cart();
- // Duplication of code in wpsc_submit_checkout, removes all shipping, tax & validation related routines
- do_action( 'wpsc_before_submit_checkout' );
- $sessionid = (mt_rand( 100, 999 ) . time());
- wpsc_update_customer_meta( 'checkout_session_id', $sessionid );
- $wpsc_checkout = new wpsc_checkout();
- $submitted_gateway = 'paypal-digital-goods'; // Only allow one payment gateway for now
- // Keep track of tax if taxes are exclusive
- $wpec_taxes_controller = new wpec_taxes_controller();
- if ( ! $wpec_taxes_controller->wpec_taxes_isincluded() ) {
- $tax = $wpsc_cart->calculate_total_tax();
- $tax_percentage = $wpsc_cart->tax_percentage;
- } else {
- $tax = 0.00;
- $tax_percentage = 0.00;
- }
- $total = $wpsc_cart->calculate_total_price();
- $args = array(
- 'totalprice' => $total,
- 'statusno' => '0',
- 'sessionid' => $sessionid,
- 'user_ID' => $current_user->ID, // This should be set in WPOAuthProvider::plugins_loaded()
- 'date' => time(),
- 'gateway' => $submitted_gateway,
- 'billing_country' => $wpsc_cart->selected_country,
- 'shipping_country' => $wpsc_cart->delivery_country,
- 'billing_region' => $wpsc_cart->selected_region,
- 'shipping_region' => $wpsc_cart->delivery_region,
- 'base_shipping' => 0,
- 'shipping_method' => '',
- 'shipping_option' => '',
- 'plugin_version' => WPSC_VERSION,
- 'discount_value' => $wpsc_cart->coupons_amount,
- 'discount_data' => $wpsc_cart->coupons_name,
- 'find_us' => '',
- 'wpec_taxes_total' => $tax,
- 'wpec_taxes_rate' => $tax_percentage
- );
- $purchase_log = new WPSC_Purchase_Log( $args );
- $purchase_log->save();
- $purchase_log_id = $purchase_log->get( 'id' );
- $wpsc_checkout->save_forms_to_db( $purchase_log_id );
- $wpsc_cart->save_to_db( $purchase_log_id );
- $wpsc_cart->submit_stock_claims( $purchase_log_id );
- $wpsc_cart->log_id = $purchase_log_id;
- do_action( 'wpsc_submit_checkout', array( 'purchase_log_id' => $purchase_log_id, 'our_user_id' => $current_user->ID ) );
- do_action( 'wpsc_submit_chekcout_gateway', $submitted_gateway, $purchase_log );
- // Submit to PayPal Digital Goods to request token
- $options = array(
- 'cancel_url' => add_query_arg( array( 'cancel_payment' => $product->get_slug() ), $return_url )
- );
- $gateway = wpsc_get_payment_gateway( $submitted_gateway );
- $gateway->gateway->set_options( $options );
- $gateway->set_purchase_log( new WPSC_Purchase_Log( $purchase_log_id ) );
- $checkout_url = $gateway->process( array( 'return_only' => true ) );
- // Store the confirmed_payment_redirect URL for this transaction
- set_transient( 'wpec_payment_details_' . $sessionid, array( 'redirect_uri' => $return_url, 'product_slug' => $product->get_slug() ), 60 * 60 );
- return $checkout_url;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement