/**
 * Manual Payment
 *
 * @access      private
 * @since       1.0 
 * @return      void
*/
function edd_manual_payment($purchase_data)
{
    global $edd_options;
    /* 
    * purchase data comes in like this
    *
    $purchase_data = array(
    	'downloads' => array of download IDs,
    	'price' => total price of cart contents,
    	'purchase_key' =>  // random key
    	'user_email' => $user_email,
    	'date' => date('Y-m-d H:i:s'),
    	'user_id' => $user_id,
    	'post_data' => $_POST,
    	'user_info' => array of user's information and used discount code
    	'cart_details' => array of cart details,
    );
    */
    $payment = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => $edd_options['currency'], 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'status' => 'pending');
    // record the pending payment
    $payment = edd_insert_payment($payment);
    if ($payment) {
        edd_update_payment_status($payment, 'publish');
        // empty the shopping cart
        edd_empty_cart();
        edd_send_to_success_page();
    } else {
        // if errors are present, send the user back to the purchase page so they can be corrected
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    }
}
/**
 * Process the payment through Payza
 *
 * @param array   $purchase_data
 */
function edds_process_payza_payment($purchase_data)
{
    global $edd_options;
    // record the pending payment
    $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'cart_details' => $purchase_data['cart_details'], 'user_info' => $purchase_data['user_info'], 'status' => 'pending');
    // Inserts a new payment
    $payment = edd_insert_payment($payment_data);
    if ($payment) {
        require_once 'payza.gateway.php';
        // Request details
        $merchant_id = trim($edd_options['payza_merchant_id']);
        $currency = edd_get_currency();
        $return_url = edd_get_success_page_url('?payment-confirmation=payza');
        $cancel_url = edd_get_failed_transaction_uri();
        $ipn_url = trailingslashit(home_url()) . '?edd-listener=PAYZA_IPN';
        // Create a new instance of the mb class
        $payza = new wp_payza_gateway($merchant_id, 'item', $currency, $return_url, $cancel_url, $ipn_url, edd_is_test_mode());
        // Get a new session ID
        $redirect_url = $payza->transaction($payment, $purchase_data['cart_details']);
        if ($redirect_url) {
            // Redirects the user
            wp_redirect($redirect_url);
            exit;
        } else {
            edd_send_back_to_checkout('?payment-mode=payza');
        }
    } else {
        edd_send_back_to_checkout('?payment-mode=payza');
    }
}
function gateway_function_to_process_payment($purchase_data)
{
    // payment processing happens here
    // if (edd_is_test_mode()) {
    //
    // } else {
    //
    // }
    $purchase_summary = edd_get_purchase_summary($purchase_data);
    // var_dump($purchase_data);
    $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'cart_details' => $purchase_data['cart_details'], 'user_info' => $purchase_data['user_info'], 'status' => 'pending');
    // echo $purchase_data['purchase_key'];
    // Record the pending payment
    $payment = edd_insert_payment($payment_data);
    // Setup Yandex.Kassa arguments
    $yandex_args = array('ShopID' => edd_get_option('ya_shop_id', false), 'scid' => edd_get_option('ya_scid', false), 'cps_email' => $purchase_data['user_email'], 'Sum' => $purchase_data['price'], 'orderNumber' => $purchase_data['purchase_key'], 'orderDetails' => $purchase_data['cart_details'], 'CustName' => $purchase_data['user_info']['first_name'], 'paymentType' => 'AC');
    // Build query
    $yandex_redirect = 'https://money.yandex.ru/eshop.xml?';
    $yandex_redirect .= http_build_query($yandex_args);
    // Redirect
    // wp_redirect( $yandex_redirect );
    // if the merchant payment is complete, set a flag
    $merchant_payment_confirmed = false;
    if ($merchant_payment_confirmed) {
        // this is used when processing credit cards on site
        // once a transaction is successful, set the purchase to complete
        edd_update_payment_status($payment, 'complete');
        // go to the success page
        edd_send_to_success_page();
    } else {
        $fail = true;
        // payment wasn't recorded
    }
}
function edd_process_paymentwall_purchase($purchase_data)
{
    global $edd_options;
    // Collect payment data
    $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'gateway' => 'paymentwall', 'status' => 'pending');
    // Record the pending payment
    $payment = edd_insert_payment($payment_data);
    // Check payment
    if (!$payment) {
        // Record the error
        edd_record_gateway_error(__('Payment Error', 'edd'), sprintf(__('Payment creation failed before sending buyer to Paymentwall. Payment data: %s', 'edd'), json_encode($payment_data)), $payment);
        // Problems? send back
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    } else {
        edd_initialize_paymentwall_lib();
        $widget = new Paymentwall_Widget($purchase_data['user_email'], $edd_options['paymentwall_widget_code'], array(new Paymentwall_Product($payment, $purchase_data['price'], edd_get_currency(), stripslashes(html_entity_decode(wp_strip_all_tags(edd_get_purchase_summary($purchase_data, false)), ENT_COMPAT, 'UTF-8')))), array('success_url' => add_query_arg('payment-confirmation', 'paymentwall', get_permalink($edd_options['success_page'])), 'email' => $purchase_data['user_email'], 'sign_version' => Paymentwall_Signature_Abstract::VERSION_THREE, 'integration_module' => 'easy_digital_downloads'));
        // Get rid of cart contents
        edd_empty_cart();
        if (!empty($edd_options['paymentwall_widget_mode']) && $edd_options['paymentwall_widget_mode'] == 'iframe') {
            echo $htmlCode = $widget->getHtmlCode(array('width' => '100%', 'allowtransparency' => 'true'));
        } else {
            wp_redirect($widget->getUrl());
        }
        exit;
    }
}
Example #5
0
/**
 * Processes the purchase data and uses the Manual Payment gateway to record
 * the transaction in the Purchase History
 *
 * @since 1.0
 * @param array $purchase_data Purchase Data
 * @return void
*/
function edd_manual_payment($purchase_data)
{
    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'edd-gateway')) {
        wp_die(__('Nonce verification has failed', 'edd'), __('Error', 'edd'), array('response' => 403));
    }
    /*
    * Purchase data comes in like this
    *
    $purchase_data = array(
    	'downloads' => array of download IDs,
    	'price' => total price of cart contents,
    	'purchase_key' =>  // Random key
    	'user_email' => $user_email,
    	'date' => date('Y-m-d H:i:s'),
    	'user_id' => $user_id,
    	'post_data' => $_POST,
    	'user_info' => array of user's information and used discount code
    	'cart_details' => array of cart details,
    );
    */
    $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'status' => 'pending');
    // Record the pending payment
    $payment = edd_insert_payment($payment_data);
    if ($payment) {
        edd_update_payment_status($payment, 'publish');
        // Empty the shopping cart
        edd_empty_cart();
        edd_send_to_success_page();
    } else {
        edd_record_gateway_error(__('Payment Error', 'edd'), sprintf(__('Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'edd'), json_encode($payment_data)), $payment);
        // If errors are present, send the user back to the purchase page so they can be corrected
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    }
}
/**
 * Process PayPal Purchase
 *
 * @since 1.0
 * @global $edd_options Array of all the EDD Options
 * @param array $purchase_data Purchase Data
 * @return void
 */
function edd_process_paypal_purchase($purchase_data)
{
    global $edd_options;
    // Check there is a gateway name
    if (!isset($purchase_data['post_data']['edd-gateway'])) {
        return;
    }
    /*
    Purchase data comes in like this:
    
    $purchase_data = array(
        'downloads'     => array of download IDs,
        'tax' 			=> taxed amount on shopping cart
        'subtotal'		=> total price before tax
        'price'         => total price of cart contents after taxes,
        'purchase_key'  =>  // Random key
        'user_email'    => $user_email,
        'date'          => date( 'Y-m-d H:i:s' ),
        'user_id'       => $user_id,
        'post_data'     => $_POST,
        'user_info'     => array of user's information and used discount code
        'cart_details'  => array of cart details,
     );
    */
    // Collect payment data
    $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'status' => 'pending');
    // Record the pending payment
    $payment = edd_insert_payment($payment_data);
    // Check payment
    if (!$payment) {
        // Record the error
        edd_record_gateway_error(__('Payment Error', 'edd'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'edd'), json_encode($payment_data)), $payment);
        // Problems? send back
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    } else {
        // Only send to PayPal if the pending payment is created successfully
        $listener_url = trailingslashit(home_url()) . '?edd-listener=IPN';
        // Get the success url
        $return_url = add_query_arg('payment-confirmation', 'paypal', get_permalink($edd_options['success_page']));
        // Get the complete cart cart_summary
        $summary = edd_get_purchase_summary($purchase_data, false);
        // Get the PayPal redirect uri
        $paypal_redirect = trailingslashit(edd_get_paypal_redirect()) . '?';
        // Setup PayPal arguments
        $paypal_args = array('cmd' => '_xclick', 'amount' => round($purchase_data['price'] - $purchase_data['tax'], 2), 'business' => $edd_options['paypal_email'], 'item_name' => stripslashes_deep(html_entity_decode(wp_strip_all_tags($summary), ENT_COMPAT, 'UTF-8')), 'email' => $purchase_data['user_email'], 'no_shipping' => '1', 'shipping' => '0', 'no_note' => '1', 'currency_code' => edd_get_currency(), 'item_number' => $purchase_data['purchase_key'], 'charset' => get_bloginfo('charset'), 'custom' => $payment, 'rm' => '2', 'return' => $return_url, 'cancel_return' => edd_get_failed_transaction_uri(), 'notify_url' => $listener_url, 'page_style' => edd_get_paypal_page_style());
        if (edd_use_taxes()) {
            $paypal_args['tax'] = $purchase_data['tax'];
        }
        $paypal_args = apply_filters('edd_paypal_redirect_args', $paypal_args, $purchase_data);
        // Build query
        $paypal_redirect .= http_build_query($paypal_args);
        // Get rid of cart contents
        edd_empty_cart();
        // Redirect to PayPal
        wp_redirect($paypal_redirect);
        exit;
    }
}
/**
 * Process PayPal Purchase
 *
 * @access      private
 * @since       1.0 
 * @return      void
*/
function edd_process_paypal_purchase($purchase_data)
{
    global $edd_options;
    // check there is a gateway name
    if (!isset($purchase_data['post_data']['edd-gateway'])) {
        return;
    }
    /* 
    Purchase data comes in like this:
    ////////////////////////////////
    
    $purchase_data = array( 
        'downloads'     => array of download IDs, 
        'price'         => total price of cart contents, 
        'purchase_key'  =>  // random key
        'user_email'    => $user_email, 
        'date'          => date( 'Y-m-d H:i:s' ), 
        'user_id'       => $user_id, 
        'post_data'     => $_POST, 
        'user_info'     => array of user's information and used discount code
        'cart_details'  => array of cart details, 
     );
    */
    // collect payment data
    $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => $edd_options['currency'], 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'status' => 'pending');
    // record the pending payment
    $payment = edd_insert_payment($payment_data);
    // check payment
    if (!$payment) {
        // problems? send back
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    } else {
        // only send to PayPal if the pending payment is created successfully
        $listener_url = trailingslashit(home_url()) . '?edd-listener=IPN';
        // get the success url
        $return_url = add_query_arg('payment-confirmation', 'paypal', get_permalink($edd_options['success_page']));
        // get the complete cart summary
        $cart_summary = edd_get_purchase_summary($purchase_data, false);
        // get the PayPal redirect uri
        $paypal_redirect = trailingslashit(edd_get_paypal_redirect()) . '?';
        // setup PayPal arguments
        $paypal_args = array('cmd' => '_xclick', 'amount' => $purchase_data['price'], 'business' => $edd_options['paypal_email'], 'item_name' => stripslashes_deep(html_entity_decode($cart_summary, ENT_COMPAT, 'UTF-8')), 'email' => $purchase_data['user_email'], 'no_shipping' => '1', 'shipping' => '0', 'no_note' => '1', 'currency_code' => $edd_options['currency'], 'item_number' => $purchase_data['purchase_key'], 'charset' => get_bloginfo('charset'), 'custom' => $payment, 'rm' => '2', 'return' => $return_url, 'notify_url' => $listener_url);
        // build query
        $paypal_redirect .= http_build_query(apply_filters('edd_paypal_redirect_args', $paypal_args, $purchase_data));
        // get rid of cart contents
        edd_empty_cart();
        // Redirect to PayPal
        wp_redirect($paypal_redirect);
        exit;
    }
}
function pw_edd_process_payment($purchase_data)
{
    global $edd_options;
    /**********************************
     * set transaction mode
     **********************************/
    if (edd_is_test_mode()) {
        $paytm_redirect = 'https://pguat.paytm.com/oltp-web/processTransaction?';
    } else {
        if ($edd_options['paytm_select_mode'] == '1') {
            $paytm_redirect = 'https://secure.paytm.in/oltp-web/processTransaction?';
        } else {
            $paytm_redirect = 'https://pguat.paytm.com/oltp-web/processTransaction?';
        }
    }
    // check for any stored errors
    $errors = edd_get_errors();
    if (!$errors) {
        $purchase_summary = edd_get_purchase_summary($purchase_data);
        /****************************************
         * setup the payment details to be stored
         ****************************************/
        $payment = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => $edd_options['currency'], 'downloads' => $purchase_data['downloads'], 'gateway' => 'paytm', 'cart_details' => $purchase_data['cart_details'], 'user_info' => $purchase_data['user_info'], 'status' => 'pending');
        // record the pending payment
        $payment = edd_insert_payment($payment);
        $merchant_payment_confirmed = false;
        $secret_key = $edd_options['paytm_mer_access_key'];
        $params = array('REQUEST_TYPE' => 'DEFAULT', 'MID' => $edd_options['paytm_merchant_id'], 'TXN_AMOUNT' => $purchase_data['price'], 'CHANNEL_ID' => "WEB", 'INDUSTRY_TYPE_ID' => $edd_options['paytm_industry_type'], 'WEBSITE' => $edd_options['paytm_website_name'], 'CUST_ID' => $purchase_data['user_email'], 'ORDER_ID' => $purchase_data['purchase_key'], 'EMAIL' => $purchase_data['user_email']);
        if ($edd_options['paytm_callback'] == '1') {
            $params['CALLBACK_URL'] = get_site_url() . '/?edd-listener=PAYTM_IPN&payment_id=' . $payment;
        }
        $checksum = getChecksumFromArray($params, $secret_key);
        $params['CHECKSUMHASH'] = $checksum;
        foreach ($params as $key => $val) {
            $submit_Params .= trim($key) . '=' . trim(urlencode($val)) . '&';
        }
        $submit_Params = substr($submit_Params, 0, -1);
        $request = $paytm_redirect . $submit_Params;
        wp_redirect($request);
        exit;
    } else {
        $fail = true;
        // errors were detected
    }
    if ($fail !== false) {
        // if errors are present, send the user back to the purchase page so they can be corrected
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    }
}
function sofort_process_payment($purchase_data)
{
    global $edd_options;
    // check there is a gateway name
    if (!isset($purchase_data['post_data']['edd-gateway'])) {
        return;
    }
    // collect payment data
    $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => $edd_options['currency'], 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'status' => 'pending');
    $errors = edd_get_errors();
    if ($errors) {
        // problems? send back
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    } else {
        $payment = edd_insert_payment($payment_data);
        // check payment
        if (!$payment) {
            edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
        } else {
            if (!class_exists('SofortLib')) {
                require_once 'library/sofortLib.php';
            }
            $return_url = add_query_arg('payment-confirmation', 'paypal', get_permalink($edd_options['success_page']));
            $Sofort = new SofortLib_Multipay(trim($edd_options['sofort_config_id']));
            $Sofort->setSofortueberweisung();
            $Sofort->setAmount($purchase_data['price']);
            $Sofort->setReason('CartId ' . $payment, $purchase_data['post_data']['edd_first'] . ' ' . $purchase_data['post_data']['edd_last']);
            $Sofort->addUserVariable($payment);
            $Sofort->setSuccessUrl($return_url);
            $Sofort->setAbortUrl(edd_get_failed_transaction_uri());
            $Sofort->setTimeoutUrl(edd_get_failed_transaction_uri());
            $Sofort->setNotificationUrl(home_url('/?sofort=ipn'));
            $Sofort->sendRequest();
            if ($Sofort->isError()) {
                //PNAG-API didn't accept the data
                wp_die($Sofort->getError(), 'Error');
            } else {
                //buyer must be redirected to $paymentUrl else payment cannot be successfully completed!
                $paymentUrl = $Sofort->getPaymentUrl();
                edd_empty_cart();
                wp_redirect($paymentUrl);
                exit;
            }
        }
    }
}
Example #10
0
/**
 * Process PayPal Purchase
 *
 * @access      private
 * @since       1.0 
 * @return      void
*/
function edd_process_paypal_purchase($purchase_data)
{
    global $edd_options;
    /* 
    * purchase data comes in like this
    *
    $purchase_data = array(
    	'downloads' => array of download IDs,
    	'price' => total price of cart contents,
    	'purchase_key' =>  // random key
    	'user_email' => $user_email,
    	'date' => date('Y-m-d H:i:s'),
    	'user_id' => $user_id,
    	'post_data' => $_POST,
    	'user_info' => array of user's information and used discount code
    	'cart_details' => array of cart details,
    );
    */
    $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => $edd_options['currency'], 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'status' => 'pending');
    // record the pending payment
    $payment = edd_insert_payment($payment_data);
    if ($payment) {
        // only send to paypal if the pending payment is created successfully
        $listener_url = trailingslashit(home_url()) . '?edd-listener=IPN';
        $return_url = add_query_arg('payment-confirmation', 'paypal', get_permalink($edd_options['success_page']));
        $cart_summary = edd_get_purchase_summary($purchase_data, false);
        // one time payment
        if (edd_is_test_mode()) {
            $paypal_redirect = 'https://www.sandbox.paypal.com/cgi-bin/webscr/?';
        } else {
            $paypal_redirect = 'https://www.paypal.com/cgi-bin/webscr/?';
        }
        $paypal_args = array('cmd' => '_xclick', 'amount' => $purchase_data['price'], 'business' => $edd_options['paypal_email'], 'item_name' => $cart_summary, 'email' => $purchase_data['user_email'], 'no_shipping' => '1', 'no_note' => '1', 'currency_code' => $edd_options['currency'], 'item_number' => $purchase_data['purchase_key'], 'charset' => 'UTF-8', 'custom' => $payment, 'rm' => '2', 'return' => $return_url, 'notify_url' => $listener_url);
        //var_dump(http_build_query($paypal_args)); exit;
        $paypal_redirect .= http_build_query($paypal_args);
        //var_dump(urldecode($paypal_redirect)); exit;
        // get rid of cart contents
        edd_empty_cart();
        // Redirect to paypal
        wp_redirect($paypal_redirect);
        exit;
    } else {
        // if errors are present, send the user back to the purchase page so they can be corrected
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    }
}
 /**
  * Process the purchase data and send to Payeezy
  *
  * @since 1.0
  * @return void
  */
 public function process_payment($purchase_data)
 {
     global $edd_options;
     $url = edd_is_test_mode() ? 'https://api-cert.payeezy.com/v1/transactions' : 'https://api.payeezy.com/v1/transactions';
     $payeezy = new Payeezy();
     $payeezy::setApiKey(edd_get_option('payeezy_api_key'));
     $payeezy::setApiSecret(edd_get_option('payeezy_api_secret'));
     $payeezy::setMerchantToken(edd_get_option('payeezy_token'));
     $payeezy::setUrl($url);
     $month = $purchase_data['card_info']['card_exp_month'];
     $month = $month > 9 ? $month : '0' . $month;
     // Payeezy requires two digits
     $year = substr($purchase_data['card_info']['card_exp_year'], -2);
     $card_type = edd_detect_cc_type($purchase_data['card_info']['card_number']);
     switch ($card_type) {
         case 'amex':
             $card_type = 'American Express';
             break;
     }
     $response = json_decode($payeezy->purchase(array('amount' => $purchase_data['price'], 'card_number' => $purchase_data['card_info']['card_number'], 'card_type' => $card_type, 'card_holder_name' => $purchase_data['card_info']['card_name'], 'card_cvv' => $purchase_data['card_info']['card_cvc'], 'card_expiry' => $month . $year, 'currency_code' => 'USD')));
     if ('failed' === $response->validation_status) {
         foreach ($response->Error->messages as $error) {
             edd_set_error($error->code, $error->description);
         }
         edd_send_back_to_checkout('?payment-mode=payeezy');
     } elseif ('success' === $response->validation_status) {
         if ('approved' === $response->transaction_status) {
             $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['post_data']['edd_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'cart_details' => $purchase_data['cart_details'], 'user_info' => $purchase_data['user_info'], 'status' => 'pending');
             // record the pending payment
             $payment_id = edd_insert_payment($payment_data);
             edd_update_payment_status($payment_id, 'publish');
             edd_set_payment_transaction_id($payment_id, $response->transaction_id);
             // Empty the shopping cart
             edd_empty_cart();
             edd_send_to_success_page();
         } else {
             edd_set_error('payeezy_error', sprintf(__('Transaction not approved. Status: %s', 'edd-payeezy'), $response->transaction_status));
             edd_send_back_to_checkout('?payment-mode=payeezy');
         }
     }
 }
function edd_fd_process_payment($purchase_data)
{
    global $edd_options;
    // setup gateway appropriately for test mode
    if (edd_is_test_mode()) {
        $endpoint = 'https://api.demo.globalgatewaye4.firstdata.com/transaction/v11/wsdl';
    } else {
        $endpoint = 'https://api.globalgatewaye4.firstdata.com/transaction/v11/wsdl';
    }
    // check the posted cc deails
    $cc = edd_fd_check_cc_details($purchase_data);
    // fcheck for errors before we continue to processing
    if (!edd_get_errors()) {
        $purchase_summary = edd_get_purchase_summary($purchase_data);
        $payment = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'cart_details' => $purchase_data['cart_details'], 'user_info' => $purchase_data['user_info'], 'status' => 'pending');
        // record the pending payment
        $payment = edd_insert_payment($payment);
        $address = esc_textarea($_POST['card_address'] . ' ' . $_POST['card_address_2'] . '|' . $_POST['card_zip'] . '|' . $_POST['card_city'] . '|' . $_POST['card_state'] . '|' . $_POST['billing_country']);
        $firstdata['Transaction'] = array('ExactID' => $edd_options['firstdata_gateway_id'], 'Password' => $edd_options['firstdata_gateway_password'], 'Transaction_Type' => $edd_options['firstdata_transaction_type'], 'DollarAmount' => $purchase_data['price'], 'Card_Number' => $cc['card_number'], 'Expiry_Date' => $cc['card_exp_month'] . $cc['card_exp_year'], 'CardHoldersName' => $cc['card_name'], 'VerificationStr1' => $address, 'VerificationStr2' => $cc['card_cvc'], 'CVD_Presence_Ind' => 1, 'Reference_No' => $payment, 'ZipCode' => $cc['card_zip'], 'Customer_Ref' => $purchase_data['user_info']['id'], 'Client_IP' => $_SERVER['REMOTE_ADDR'], 'Client_Email' => $purchase_data['user_email'], 'Currency' => $edd_options['currency'], 'Ecommerce_Flag' => is_ssl() ? 8 : 7);
        try {
            $api = @new SoapClient($endpoint);
            $result = $api->__soapCall('SendAndCommit', $firstdata);
        } catch (Exception $e) {
            edd_set_error('firstdata_api_error', sprintf(__('FirstData System Error: %s', 'edd_firstdata'), $e->getMessage()));
            edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
            $fail = true;
        }
        if (isset($result) && $result->Transaction_Approved) {
            edd_update_payment_status($payment, 'complete');
            edd_send_to_success_page();
        } elseif ($result->Transaction_Error) {
            edd_set_error('firstdata_decline', sprintf(__('Transaction Declined: %s', 'edd_firstdata'), $result->EXact_Message));
            edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
            $fail = true;
        }
    } else {
        $fail = true;
    }
}
 /**
  * Process Payment
  *
  * Process payments trough the PagSeguro gateway.
  *
  * @return   void
  * @since    1.0
  */
 function process_payment($purchase_data)
 {
     global $edd_options;
     // check there is a gateway name
     if (!isset($purchase_data['post_data']['edd-gateway'])) {
         return;
     }
     // get credentials
     $credentials = $this->get_credentials();
     // check credentials have been set
     if (is_null($credentials['email']) || is_null($credentials['token'])) {
         edd_set_error(0, __('Please enter your PagSeguro Client Email and Token in settings', 'edd-pagseguro-gateway'));
         edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
     }
     // get payment
     $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_option('currency', 'BRL'), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'status' => 'pending');
     // insert pending payment
     $payment = edd_insert_payment($payment_data);
     if (!$payment) {
         // problems? send back
         edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
     } else {
         // require PagSeguro files
         $this->load_pagseguro_sdk();
         // verify classes exists
         if (!class_exists('PagSeguroPaymentRequest')) {
             edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
         }
         // create payment request
         $paymentRequest = new PagSeguroPaymentRequest();
         // sets the currency
         $paymentRequest->setCurrency('BRL');
         // cart summary
         $cart_summary = edd_get_purchase_summary($purchase_data, false);
         // format total price
         $total_price = number_format($purchase_data['price'], 2, '.', '');
         // payment request details
         $paymentRequest->addItem('01', sanitize_text_field(substr($cart_summary, 0, 95)), '1', strval($total_price));
         // sets the reference code for this request
         $paymentRequest->setReference($payment);
         // sets customer information
         $paymentRequest->setSender(sanitize_text_field($purchase_data['user_info']['first_name'] . ' ' . $purchase_data['user_info']['last_name']), $purchase_data['user_email']);
         // redirect url
         $paymentRequest->setRedirectUrl(add_query_arg('payment-confirmation', 'pagseguro', edd_get_success_page_uri()));
         // IPN URL
         $paymentRequest->addParameter('notificationURL', get_site_url());
         /* TRY CHECKOUT */
         try {
             // generate credentials
             $credentials = new PagSeguroAccountCredentials($credentials['email'], $credentials['token']);
             // register this payment request in PagSeguro, to obtain the payment URL for redirect your customer
             $checkout_uri = $paymentRequest->register($credentials);
             if (gettype($checkout_uri) != 'string') {
                 throw new exception($checkout_uri);
             }
             // empty cart
             edd_empty_cart();
             // send the user to PagSeguro
             wp_redirect($checkout_uri);
             die;
         } catch (Exception $e) {
             //catch exception
             wp_mail(get_bloginfo('admin_email'), __('PagSeguro Checkout Error', 'edd-pagseguro-gateway'), $e->getMessage());
             edd_set_error('pagseguro_exception', $e->getMessage());
             edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
         }
     }
 }
 /**
  * Process payment submission
  *
  * @access      public
  * @since       1.0.0
  * @param       array $purchase_data The data for a specific purchase
  * @return      void
  */
 public function process_payment($purchase_data)
 {
     if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'edd-gateway')) {
         wp_die(__('Nonce verification has failed', 'edd-wallet'), __('Error', 'edd-wallet'), array('response' => 403));
     }
     $error = false;
     // Double check that we can afford this item
     $value = edd_wallet()->wallet->balance($purchase_data['user_email']);
     if ($value < $purchase_data['price']) {
         edd_record_gateway_error(__('Wallet Gateway Error', 'edd-wallet'), __('User wallet has insufficient funds.', 'edd-wallet'), 0);
         edd_set_error('wallet_error', __('Insufficient funds.', 'edd-wallet'));
         edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
     }
     $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'status' => 'pending');
     // Record the pending payment
     $payment = edd_insert_payment($payment_data);
     if ($payment) {
         // Update payment status
         edd_update_payment_status($payment, 'publish');
         // Withdraw the funds
         edd_wallet()->wallet->withdraw($purchase_data['user_info']['id'], $payment_data['price'], 'withdrawal', $payment);
         edd_empty_cart();
         edd_send_to_success_page();
     } else {
         edd_record_gateway_error(__('Wallet Gateway Error', 'edd-wallet'), sprintf(__('Payment creation failed while processing a Wallet purchase. Payment data: %s', 'edd-wallet'), json_encode($payment_data)), $payment);
         edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
     }
 }
Example #15
0
 /**
  * Record a subscription payment
  *
  * @since  1.0.1
  * @return void
  */
 public function record_subscription_payment($parent_id = 0, $amount = '', $txn_id = '', $unique_key = 0)
 {
     global $edd_options;
     if ($this->payment_exists($unique_key)) {
         return;
     }
     // increase the earnings for each product in the subscription
     $downloads = edd_get_payment_meta_downloads($parent_id);
     if ($downloads) {
         foreach ($downloads as $download) {
             edd_increase_earnings($download['id'], $amount);
         }
     }
     // setup the payment daya
     $payment_data = array('parent' => $parent_id, 'price' => $amount, 'user_email' => edd_get_payment_user_email($parent_id), 'purchase_key' => get_post_meta($parent_id, '_edd_payment_purchase_key', true), 'currency' => edd_get_option('currency', 'usd'), 'downloads' => $downloads, 'user_info' => edd_get_payment_meta_user_info($parent_id), 'cart_details' => edd_get_payment_meta_cart_details($parent_id), 'status' => 'edd_subscription', 'gateway' => edd_get_payment_gateway($parent_id));
     // record the subscription payment
     $payment = edd_insert_payment($payment_data);
     if (!empty($unique_key)) {
         update_post_meta($payment, '_edd_recurring_' . $unique_key, '1');
     }
     // Record transaction ID
     if (!empty($txn_id)) {
         if (function_exists('edd_set_payment_transaction_id')) {
             edd_set_payment_transaction_id($payment, $txn_id);
         }
     }
     // Update the expiration date of license keys, if EDD Software Licensing is active
     if (function_exists('edd_software_licensing')) {
         $licenses = edd_software_licensing()->get_licenses_of_purchase($parent_id);
         if (!empty($licenses)) {
             foreach ($licenses as $license) {
                 // Update the expiration dates of the license key
                 edd_software_licensing()->renew_license($license->ID, $parent_id);
             }
         }
     }
     do_action('edd_recurring_record_payment', $payment, $parent_id, $amount, $txn_id, $unique_key);
 }
Example #16
0
/**
 * Process stripe checkout submission
 *
 * @access      public
 * @since       1.0
 * @return      void
 */
function edds_process_stripe_payment($purchase_data)
{
    global $edd_options;
    if (!class_exists('Stripe')) {
        require_once EDDS_PLUGIN_DIR . '/Stripe/Stripe.php';
    }
    if (edd_is_test_mode()) {
        $secret_key = trim($edd_options['test_secret_key']);
    } else {
        $secret_key = trim($edd_options['live_secret_key']);
    }
    $purchase_summary = edd_get_purchase_summary($purchase_data, false);
    // make sure we don't have any left over errors present
    edd_clear_errors();
    if (!isset($_POST['edd_stripe_token'])) {
        // check for fallback mode
        if (isset($edd_options['stripe_js_fallback'])) {
            if (!isset($_POST['card_name']) || strlen(trim($_POST['card_name'])) == 0) {
                edd_set_error('no_card_name', __('Please enter a name for the credit card.', 'edds'));
            }
            if (!isset($_POST['card_number']) || strlen(trim($_POST['card_number'])) == 0) {
                edd_set_error('no_card_number', __('Please enter a credit card number.', 'edds'));
            }
            if (!isset($_POST['card_cvc']) || strlen(trim($_POST['card_cvc'])) == 0) {
                edd_set_error('no_card_cvc', __('Please enter a CVC/CVV for the credit card.', 'edds'));
            }
            if (!isset($_POST['card_exp_month']) || strlen(trim($_POST['card_exp_month'])) == 0) {
                edd_set_error('no_card_exp_month', __('Please enter a expiration month.', 'edds'));
            }
            if (!isset($_POST['card_exp_year']) || strlen(trim($_POST['card_exp_year'])) == 0) {
                edd_set_error('no_card_exp_year', __('Please enter a expiration year.', 'edds'));
            }
            $card_data = array('number' => $purchase_data['card_info']['card_number'], 'name' => $purchase_data['card_info']['card_name'], 'exp_month' => $purchase_data['card_info']['card_exp_month'], 'exp_year' => $purchase_data['card_info']['card_exp_year'], 'cvc' => $purchase_data['card_info']['card_cvc'], 'address_line1' => $purchase_data['card_info']['card_address'], 'address_line2' => $purchase_data['card_info']['card_address_2'], 'address_city' => $purchase_data['card_info']['card_city'], 'address_zip' => $purchase_data['card_info']['card_zip'], 'address_state' => $purchase_data['card_info']['card_state'], 'address_country' => $purchase_data['card_info']['card_country']);
        } else {
            // no Stripe token
            edd_set_error('no_token', __('Missing Stripe token. Please contact support.', 'edds'));
            edd_record_gateway_error(__('Missing Stripe Token', 'edds'), __('A Stripe token failed to be generated. Please check Stripe logs for more information', ' edds'));
        }
    } else {
        $card_data = $_POST['edd_stripe_token'];
    }
    $errors = edd_get_errors();
    if (!$errors) {
        try {
            Stripe::setApiKey($secret_key);
            // setup the payment details
            $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'cart_details' => $purchase_data['cart_details'], 'user_info' => $purchase_data['user_info'], 'status' => 'pending', 'gateway' => 'stripe');
            $customer_exists = false;
            if (is_user_logged_in()) {
                $user = get_user_by('email', $purchase_data['user_email']);
                if ($user) {
                    $customer_id = get_user_meta($user->ID, edd_stripe_get_customer_key(), true);
                    if ($customer_id) {
                        $customer_exists = true;
                        try {
                            // Update the customer to ensure their card data is up to date
                            $cu = Stripe_Customer::retrieve($customer_id);
                            if (isset($cu->deleted) && $cu->deleted) {
                                // This customer was deleted
                                $customer_exists = false;
                            } else {
                                $cu->card = $card_data;
                                $cu->save();
                            }
                            // No customer found
                        } catch (Exception $e) {
                            $customer_exists = false;
                        }
                    }
                }
            }
            if (!$customer_exists) {
                // Create a customer first so we can retrieve them later for future payments
                $customer = Stripe_Customer::create(array('description' => $purchase_data['user_email'], 'email' => $purchase_data['user_email'], 'card' => $card_data));
                $customer_id = is_array($customer) ? $customer['id'] : $customer->id;
                if (is_user_logged_in()) {
                    update_user_meta($user->ID, edd_stripe_get_customer_key(), $customer_id);
                }
            }
            if (edds_is_recurring_purchase($purchase_data) && (!empty($customer) || $customer_exists)) {
                // Process a recurring subscription purchase
                $cu = Stripe_Customer::retrieve($customer_id);
                /**********************************************************
                 * Taxes, fees, and discounts have to be handled differently
                 * with recurring subscriptions, so each is added as an
                 * invoice item and then charged as one time items
                 **********************************************************/
                $invoice_items = array();
                $needs_invoiced = false;
                if ($purchase_data['tax'] > 0 && !edd_prices_include_tax()) {
                    if (edds_is_zero_decimal_currency()) {
                        $tax = $purchase_data['tax'];
                    } else {
                        $tax = $purchase_data['tax'] * 100;
                    }
                    $invoice = Stripe_InvoiceItem::create(array('customer' => $customer_id, 'amount' => $tax, 'currency' => edd_get_currency(), 'description' => sprintf(__('Sales tax for order %s', 'edds'), $purchase_data['purchase_key'])));
                    if (!empty($invoice->id)) {
                        $invoice_items[] = $invoice->id;
                    }
                    $needs_invoiced = true;
                }
                if (!empty($purchase_data['fees'])) {
                    foreach ($purchase_data['fees'] as $fee) {
                        if (edds_is_zero_decimal_currency()) {
                            $fee_amount = $fee['amount'];
                        } else {
                            $fee_amount = $fee['amount'] * 100;
                        }
                        $invoice = Stripe_InvoiceItem::create(array('customer' => $customer_id, 'amount' => $fee_amount, 'currency' => edd_get_currency(), 'description' => $fee['label']));
                        if (!empty($invoice->id)) {
                            $invoice_items[] = $invoice->id;
                        }
                    }
                    $needs_invoiced = true;
                }
                if ($purchase_data['discount'] > 0) {
                    if (edds_is_zero_decimal_currency()) {
                        $discount_amount = $purchase_data['discount'];
                    } else {
                        $discount_amount = $purchase_data['discount'] * 100;
                    }
                    $invoice = Stripe_InvoiceItem::create(array('customer' => $customer_id, 'amount' => $discount_amount * -1, 'currency' => edd_get_currency(), 'description' => $purchase_data['user_info']['discount']));
                    if (!empty($invoice->id)) {
                        $invoice_items[] = $invoice->id;
                    }
                    $needs_invoiced = true;
                }
                try {
                    $plan_id = edds_get_plan_id($purchase_data);
                    // record the pending payment
                    $payment = edd_insert_payment($payment_data);
                    set_transient('_edd_recurring_payment_' . $payment, '1', DAY_IN_SECONDS);
                    // Store the parent payment ID in the user meta
                    EDD_Recurring_Customer::set_customer_payment_id($user->ID, $payment);
                    // Update the customer's subscription in Stripe
                    $customer_response = $cu->updateSubscription(array('plan' => $plan_id));
                    // Set user as subscriber
                    EDD_Recurring_Customer::set_as_subscriber($user->ID);
                    // store the customer recurring ID
                    EDD_Recurring_Customer::set_customer_id($user->ID, $customer_id);
                    // Set the customer status
                    EDD_Recurring_Customer::set_customer_status($user->ID, 'active');
                    // Calculate the customer's new expiration date
                    $new_expiration = EDD_Recurring_Customer::calc_user_expiration($user->ID, $payment);
                    // Set the customer's new expiration date
                    EDD_Recurring_Customer::set_customer_expiration($user->ID, $new_expiration);
                } catch (Stripe_CardError $e) {
                    $body = $e->getJsonBody();
                    $err = $body['error'];
                    if (isset($err['message'])) {
                        edd_set_error('payment_error', $err['message']);
                    } else {
                        edd_set_error('payment_error', __('There was an error processing your payment, please ensure you have entered your card number correctly.', 'edds'));
                    }
                    edd_record_gateway_error(__('Stripe Error', 'edds'), sprintf(__('There was an error while processing a Stripe payment. Payment data: %s', ' edds'), json_encode($err)), 0);
                } catch (Stripe_ApiConnectionError $e) {
                    $body = $e->getJsonBody();
                    $err = $body['error'];
                    edd_set_error('payment_error', __('There was an error processing your payment (Stripe\'s API is down), please try again', 'edds'));
                    edd_record_gateway_error(__('Stripe Error', 'edds'), sprintf(__('There was an error processing your payment (Stripe\'s API was down). Error: %s', 'edds'), json_encode($err['message'])), 0);
                } catch (Stripe_InvalidRequestError $e) {
                    $body = $e->getJsonBody();
                    $err = $body['error'];
                    // Bad Request of some sort. Maybe Christoff was here ;)
                    if (isset($err['message'])) {
                        edd_set_error('request_error', $err['message']);
                    } else {
                        edd_set_error('request_error', sprintf(__('The Stripe API request was invalid, please try again. Error: %s', 'edds'), json_encode($err['message'])));
                    }
                } catch (Stripe_ApiError $e) {
                    $body = $e->getJsonBody();
                    $err = $body['error'];
                    if (isset($err['message'])) {
                        edd_set_error('request_error', $err['message']);
                    } else {
                        edd_set_error('request_error', __('The Stripe API request was invalid, please try again', 'edds'));
                    }
                    edd_record_gateway_error(__('Stripe Error', 'edds'), sprintf(__('There was an error with Stripe\'s API: ', 'edds'), json_encode($err['message'])), 0);
                } catch (Stripe_AuthenticationError $e) {
                    $body = $e->getJsonBody();
                    $err = $body['error'];
                    // Authentication error. Stripe keys in settings are bad.
                    if (isset($err['message'])) {
                        edd_set_error('request_error', $err['message']);
                    } else {
                        edd_set_error('api_error', __('The API keys entered in settings are incorrect', 'edds'));
                    }
                } catch (Stripe_Error $e) {
                    $body = $e->getJsonBody();
                    $err = $body['error'];
                    // generic stripe error
                    if (isset($err['message'])) {
                        edd_set_error('request_error', $err['message']);
                    } else {
                        edd_set_error('api_error', __('Something went wrong.', 'edds'));
                    }
                } catch (Exception $e) {
                    // some sort of other error
                    $body = $e->getJsonBody();
                    $err = $body['error'];
                    if (isset($err['message'])) {
                        edd_set_error('request_error', $err['message']);
                    } else {
                        edd_set_error('api_error', __('Something went wrong.', 'edds'));
                    }
                }
                if (!empty($err)) {
                    // Delete any invoice items we created for fees, taxes, and other
                    foreach ($invoice_items as $invoice) {
                        $ii = Stripe_InvoiceItem::retrieve($invoice);
                        $ii->delete();
                    }
                    edd_send_back_to_checkout('?payment-mode=stripe');
                }
            } elseif (!empty($customer) || $customer_exists) {
                // Process a normal one-time charge purchase
                if (!isset($edd_options['stripe_preapprove_only'])) {
                    if (edds_is_zero_decimal_currency()) {
                        $amount = $purchase_data['price'];
                    } else {
                        $amount = $purchase_data['price'] * 100;
                    }
                    $charge = Stripe_Charge::create(array("amount" => $amount, "currency" => edd_get_currency(), "customer" => $customer_id, "description" => html_entity_decode($purchase_summary, ENT_COMPAT, 'UTF-8'), 'statement_description' => substr($purchase_summary, 0, 15), 'metadata' => array('email' => $purchase_data['user_info']['email'])));
                }
                // record the pending payment
                $payment = edd_insert_payment($payment_data);
            } else {
                edd_record_gateway_error(__('Customer Creation Failed', 'edds'), sprintf(__('Customer creation failed while processing a payment. Payment Data: %s', ' edds'), json_encode($payment_data)), $payment);
            }
            if ($payment && (!empty($customer_id) || !empty($charge))) {
                if (!empty($needs_invoiced)) {
                    try {
                        // Create the invoice containing taxes / discounts / fees
                        $invoice = Stripe_Invoice::create(array('customer' => $customer_id));
                        $invoice = $invoice->pay();
                    } catch (Exception $e) {
                        // If there is nothing to pay, it just means the invoice item was taken care of with the subscription payment
                    }
                }
                if (isset($edd_options['stripe_preapprove_only'])) {
                    edd_update_payment_status($payment, 'preapproval');
                    add_post_meta($payment, '_edds_stripe_customer_id', $customer_id);
                } else {
                    edd_update_payment_status($payment, 'publish');
                }
                // You should be using Stripe's API here to retrieve the invoice then confirming it's been paid
                if (!empty($charge)) {
                    edd_insert_payment_note($payment, 'Stripe Charge ID: ' . $charge->id);
                    if (function_exists('edd_set_payment_transaction_id')) {
                        edd_set_payment_transaction_id($payment, $charge->id);
                    }
                } elseif (!empty($customer_id)) {
                    edd_insert_payment_note($payment, 'Stripe Customer ID: ' . $customer_id);
                }
                edd_empty_cart();
                edd_send_to_success_page();
            } else {
                edd_set_error('payment_not_recorded', __('Your payment could not be recorded, please contact the site administrator.', 'edds'));
                // if errors are present, send the user back to the purchase page so they can be corrected
                edd_send_back_to_checkout('?payment-mode=stripe');
            }
        } catch (Stripe_CardError $e) {
            $body = $e->getJsonBody();
            $err = $body['error'];
            if (isset($err['message'])) {
                edd_set_error('payment_error', $err['message']);
            } else {
                edd_set_error('payment_error', __('There was an error processing your payment, please ensure you have entered your card number correctly.', 'edds'));
            }
            edd_record_gateway_error(__('Stripe Error', 'edds'), sprintf(__('There was an error while processing a Stripe payment. Payment data: %s', ' edds'), json_encode($err)), 0);
            edd_send_back_to_checkout('?payment-mode=stripe');
        } catch (Stripe_ApiConnectionError $e) {
            $body = $e->getJsonBody();
            $err = $body['error'];
            edd_set_error('payment_error', __('There was an error processing your payment (Stripe\'s API is down), please try again', 'edds'));
            edd_record_gateway_error(__('Stripe Error', 'edds'), sprintf(__('There was an error processing your payment (Stripe\'s API was down). Error: %s', 'edds'), json_encode($err['message'])), 0);
            edd_send_back_to_checkout('?payment-mode=stripe');
        } catch (Stripe_InvalidRequestError $e) {
            $body = $e->getJsonBody();
            $err = $body['error'];
            // Bad Request of some sort. Maybe Christoff was here ;)
            if (isset($err['message'])) {
                edd_set_error('request_error', $err['message']);
            } else {
                edd_set_error('request_error', __('The Stripe API request was invalid, please try again', 'edds'));
            }
            edd_send_back_to_checkout('?payment-mode=stripe');
        } catch (Stripe_ApiError $e) {
            $body = $e->getJsonBody();
            $err = $body['error'];
            if (isset($err['message'])) {
                edd_set_error('request_error', $err['message']);
            } else {
                edd_set_error('request_error', __('The Stripe API request was invalid, please try again', 'edds'));
            }
            edd_set_error('request_error', sprintf(__('The Stripe API request was invalid, please try again. Error: %s', 'edds'), json_encode($err['message'])));
            edd_send_back_to_checkout('?payment-mode=stripe');
        } catch (Stripe_AuthenticationError $e) {
            $body = $e->getJsonBody();
            $err = $body['error'];
            // Authentication error. Stripe keys in settings are bad.
            if (isset($err['message'])) {
                edd_set_error('request_error', $err['message']);
            } else {
                edd_set_error('api_error', __('The API keys entered in settings are incorrect', 'edds'));
            }
            edd_send_back_to_checkout('?payment-mode=stripe');
        } catch (Stripe_Error $e) {
            $body = $e->getJsonBody();
            $err = $body['error'];
            // generic stripe error
            if (isset($err['message'])) {
                edd_set_error('request_error', $err['message']);
            } else {
                edd_set_error('api_error', __('Something went wrong.', 'edds'));
            }
            edd_send_back_to_checkout('?payment-mode=stripe');
        } catch (Exception $e) {
            // some sort of other error
            $body = $e->getJsonBody();
            $err = $body['error'];
            if (isset($err['message'])) {
                edd_set_error('request_error', $err['message']);
            } else {
                edd_set_error('api_error', __('Something went wrong.', 'edds'));
            }
            edd_send_back_to_checkout('?payment-mode=stripe');
        }
    } else {
        edd_send_back_to_checkout('?payment-mode=stripe');
    }
}
Example #17
0
 /**
  * Make a payment
  *
  * @return bool|int Payment ID if created succefully, false if not.
  */
 protected function make_payment()
 {
     /** @var array */
     global $edd_options;
     $data = array('status' => 'publish', 'tax' => 0, 'first' => $this->user->first_name, 'last' => $this->user->last_name, 'downloads' => array());
     $user_id = $this->user->ID;
     $email = $this->user->user_email;
     $user_first = sanitize_text_field($data['first']);
     $user_last = sanitize_text_field($data['last']);
     $user_info = array('id' => $user_id, 'email' => $email, 'first_name' => $user_first, 'last_name' => $user_last, 'discount' => 'none');
     $price = 0;
     $cart_details = array();
     $total = 0;
     $download = ids::$trial_id;
     $cart_details[$download] = array('name' => get_the_title($download), 'id' => $download, 'item_number' => $download, 'price' => $price, 'subtotal' => $price, 'quantity' => 1, 'tax' => 0, 'price_id' => ids::$trial_price_id);
     $total = $price;
     $date = date('Y-m-d H:i:s', current_time('timestamp'));
     if (strtotime($date, time()) > time()) {
         $date = date('Y-m-d H:i:s', current_time('timestamp'));
     }
     $purchase_data = array('price' => edd_sanitize_amount($total), 'tax' => 0, 'post_date' => $date, 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $email, 'user_info' => $user_info, 'currency' => edd_get_currency(), 'downloads' => $data['downloads'], 'cart_details' => $cart_details, 'status' => 'pending');
     $payment_id = edd_insert_payment($purchase_data);
     $keys = \EDD_Software_Licensing::instance()->get_licenses_of_purchase($payment_id);
     if (is_array($keys) && isset($keys[0]) && is_object($keys[0])) {
         $this->license = $keys[0]->ID;
         update_post_meta($this->license, '_ingsl_is_trial', 1);
         update_post_meta($this->license, '_ingsl_upsold', 0);
     }
     // increase stats and log earnings
     edd_update_payment_status($payment_id, $data['status']);
     return $payment_id;
 }
Example #18
0
 /**
  * Process voguepay Purchase
  * @global $edd_options Array of all the EDD Options
  * @param array   $purchase_data Purchase Data
  * @return void
  */
 function process_voguepay_purchase($purchase_data)
 {
     global $edd_options;
     if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'edd-gateway')) {
         wp_die(__('Nonce verification has failed', 'edd-voguepay'), __('Error', 'edd-voguepay'), array('response' => 403));
     }
     // Collect payment data
     $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'gateway' => 'voguepay', 'status' => 'pending');
     // Add contact number if user is logged in.
     // if( is_user_logged_in() ) {
     // $user_ID = get_current_user_id();
     // Add contact number in user meta.
     // update_user_meta( $user_ID, '_edd_user_contact_info', $purchase_data[ 'post_data' ][ 'contact_number' ] );
     // }
     // Record the pending payment
     $payment = edd_insert_payment($payment_data);
     // Check payment
     if (!$payment) {
         // Record the error
         edd_record_gateway_error(__('Payment Error', 'edd-voguepay'), sprintf(__('Payment creation failed before sending buyer to Voguepay. Payment data: %s', 'edd-voguepay'), json_encode($payment_data)), $payment);
         // Problems? send back
         edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
     } else {
         // Only send to voguepay if the pending payment is created successfully
         //$listener_url = add_query_arg( 'edd-listener', 'VOGUEPAY_RESPONSE', home_url( 'index.php' ) );
         // Get the success url
         $listener_url = add_query_arg(array('edd-listener' => 'VOGUEPAY_RESPONSE', 'payment-id' => $payment), home_url('index.php'));
         // Get the voguepay redirect uri
         $voguepay_redirect = trailingslashit($this->get_voguepay_redirect());
         // Merchant ID.
         $merchant_id = $edd_options['v_merchant_id'];
         // Merchant ID.
         $store_id = $edd_options['store_id'];
         // Generate merchant ref ID.
         $merchant_ref = $this->generate_merchant_refID();
         // Checksum Method.
         $checksum_method = 'MD5';
         /* Do currency conversion. */
         // $amount = $this->do_currency_conversion( $purchase_data[ 'price' ] );
         // Round up final amount and convert amount into paisa.
         $amount = $purchase_data['price'];
         //Get server IP address.
         $ip_address = gethostbyname($_SERVER['SERVER_NAME']);
         // String to generate checksum.
         $checksum_string = $edd_options['voguepay_secret_key'] . $merchant_id . '|' . $edd_options['voguepay_apikey'] . '|' . $ip_address . '|' . $merchant_ref . '|' . 'INR' . '|' . $amount . '|' . $checksum_method . '|' . 1;
         // Generate checksum.
         $checksum = md5($checksum_string);
         // Setup voguepay arguments
         $voguepay_args = array('cur' => 'NGN', 'memo' => 'Secure Payment with VoguePay', 'total' => $amount, 'merchant_ref' => $merchant_ref, 'v_merchant_id' => $merchant_id, 'store_id' => $store_id, 'success_url' => get_permalink($edd_options['success_page']), 'fail_url' => edd_get_failed_transaction_uri('?payment-id=' . $payment), 'notify_url' => $listener_url);
         $voguepay_args = apply_filters('edd_voguepay_redirect_args', $voguepay_args, $purchase_data);
         echo '<div align="center"><br /><br /><br />';
         echo "<h3>...Redirecting. Click the image below if not automatically redirected</h3><br /><br /><br />";
         echo '<form action="' . $voguepay_redirect . '" method="POST" name="voguepayForm">';
         foreach ($voguepay_args as $arg => $arg_value) {
             echo '<input type="hidden" name="' . $arg . '" value="' . $arg_value . '">';
         }
         $seyeurl = plugins_url('assets/pay-via-voguepay.png', __FILE__);
         echo '<input type="image" src="' . $seyeurl . '" />';
         echo '</form></div>
               <script language="JavaScript">
                  //  document.voguepayForm.submit();
               </script>';
         die;
     }
 }
 /**
  * Process the purchase and create the charge in Amazon
  *
  * @access public
  * @since  2.4
  * @param  $purchase_data array Cart details
  * @return void
  */
 public function process_purchase($purchase_data)
 {
     if (empty($purchase_data['post_data']['edd_amazon_reference_id'])) {
         edd_set_error('missing_reference_id', __('Missing Reference ID, please try again', 'edd'));
     }
     $errors = edd_get_errors();
     if ($errors) {
         edd_send_back_to_checkout('?payment-mode=amazon');
     }
     $args = apply_filters('edd_amazon_charge_args', array('merchant_id' => edd_get_option('amazon_seller_id', ''), 'amazon_reference_id' => $purchase_data['post_data']['edd_amazon_reference_id'], 'authorization_reference_id' => $purchase_data['purchase_key'], 'charge_amount' => $purchase_data['price'], 'currency_code' => edd_get_currency(), 'charge_note' => html_entity_decode(edd_get_purchase_summary($purchase_data, false)), 'charge_order_id' => $purchase_data['purchase_key'], 'store_name' => remove_accents(wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)), 'transaction_timeout' => 0), $purchase_data);
     $args['platform_id'] = 'A3JST9YM1SX7LB';
     $charge = $this->client->charge($args);
     if (200 == $charge->response['Status']) {
         $charge = new ResponseParser($charge->response);
         $charge = $charge->toArray();
         $status = $charge['AuthorizeResult']['AuthorizationDetails']['AuthorizationStatus']['State'];
         if ('Declined' === $status) {
             $reason = $charge['AuthorizeResult']['AuthorizationDetails']['AuthorizationStatus']['ReasonCode'];
             edd_set_error('payment_declined', sprintf(__('Your payment could not be authorized, please try a different payment method. Reason: %s', 'edd'), $reason));
             edd_send_back_to_checkout('?payment-mode=amazon&amazon_reference_id=' . $purchase_data['post_data']['edd_amazon_reference_id']);
         }
         // Setup payment data to be recorded
         $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'gateway' => $this->gateway_id, 'status' => 'pending');
         $payment_id = edd_insert_payment($payment_data);
         $authorization_id = $charge['AuthorizeResult']['AuthorizationDetails']['AmazonAuthorizationId'];
         $capture_id = str_replace('-A', '-C', $authorization_id);
         $reference_id = sanitize_text_field($_POST['edd_amazon_reference_id']);
         // Confirm the capture was completed
         $capture = $this->client->getCaptureDetails(array('merchant_id' => edd_get_option('amazon_seller_id', ''), 'amazon_capture_id' => $capture_id));
         $capture = new ResponseParser($capture->response);
         $capture = $capture->toArray();
         // Check capture status
         edd_update_payment_meta($payment_id, '_edd_amazon_authorization_id', $authorization_id);
         edd_update_payment_meta($payment_id, '_edd_amazon_capture_id', $capture_id);
         edd_set_payment_transaction_id($payment_id, $reference_id);
         edd_update_payment_status($payment_id, 'publish');
         // Empty the shopping cart
         edd_empty_cart();
         edd_send_to_success_page();
     } else {
         // Set an error
         edd_set_error('amazon_error', sprintf(__('There was an issue processing your payment. Amazon error: %s', 'edd'), print_r($charge, true)));
         edd_send_back_to_checkout('?payment-mode=amazon&amazon_reference_id=' . $purchase_data['post_data']['edd_amazon_reference_id']);
     }
 }
function sagepay_direct_process_payment($purchase_data)
{
    global $edd_options;
    // check there is a gateway name
    if (!isset($purchase_data['post_data']['edd-gateway'])) {
        return;
    }
    // collect payment data
    $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'gateway' => 'sagepay_direct', 'status' => 'pending');
    $required = array('edd_first' => __('First Name is not entered.', 'sagepay_direct_patsatech'), 'edd_last' => __('Last Name is not entered.', 'sagepay_direct_patsatech'), 'card_cvc' => __('Card CVV is not entered.', 'sagepay_direct_patsatech'), 'card_name' => __('Card Holder Name is not entered.', 'sagepay_direct_patsatech'), 'card_address' => __('Billing Address is not entered.', 'sagepay_direct_patsatech'), 'card_city' => __('Billing City is not entered.', 'sagepay_direct_patsatech'), 'card_zip' => __('Billing Zip / Postal Code is not entered.', 'sagepay_direct_patsatech'));
    foreach ($required as $field => $error) {
        if (!$purchase_data['post_data'][$field]) {
            edd_set_error('billing_error', $error);
        }
    }
    if (!sagepay_direct_is_credit_card_number($purchase_data['post_data']['card_number'])) {
        edd_set_error('invalid_card_number', __('Credit Card Number is not valid.', 'sagepay_direct_patsatech'));
    }
    if (!sagepay_direct_is_correct_expire_date($purchase_data['post_data']['card_exp_month'], $purchase_data['post_data']['card_exp_year'])) {
        edd_set_error('invalid_card_expiry', __('Card Expire Date is not valid.', 'sagepay_direct_patsatech'));
    }
    $errors = edd_get_errors();
    if ($errors) {
        // problems? send back
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    } else {
        // record the pending payment
        $payment = edd_insert_payment($payment_data);
        // check payment
        if (!$payment) {
            // problems? send back
            edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
        } else {
            $time_stamp = date("ymdHis");
            $orderid = $edd_options['sagepay_direct_vendor_name'] . "-" . $time_stamp . "-" . $payment;
            $sp_arg['ReferrerID'] = 'CC923B06-40D5-4713-85C1-700D690550BF';
            $sp_arg['Amount'] = $purchase_data['price'];
            $sp_arg['CustomerName'] = substr($purchase_data['post_data']['edd_first'] . ' ' . $purchase_data['post_data']['edd_last'], 0, 100);
            $sp_arg['CustomerEMail'] = substr($purchase_data['post_data']['edd_email'], 0, 255);
            $sp_arg['BillingSurname'] = substr($purchase_data['post_data']['edd_last'], 0, 20);
            $sp_arg['BillingFirstnames'] = substr($purchase_data['post_data']['edd_first'], 0, 20);
            $sp_arg['BillingAddress1'] = substr($purchase_data['post_data']['card_address'], 0, 100);
            $sp_arg['BillingAddress2'] = substr($purchase_data['post_data']['card_address_2'], 0, 100);
            $sp_arg['BillingCity'] = substr($purchase_data['post_data']['card_city'], 0, 40);
            if ($purchase_data['post_data']['billing_country'] == 'US') {
                $sp_arg['BillingState'] = $purchase_data['post_data']['card_state'];
            } else {
                $sp_arg['BillingState'] = '';
            }
            $sp_arg['BillingPostCode'] = substr($purchase_data['post_data']['card_zip'], 0, 10);
            $sp_arg['BillingCountry'] = $purchase_data['post_data']['billing_country'];
            //$sp_arg['BillingPhone'] 		= substr($purchase_data['post_data']['edd_phone'], 0, 20);
            $sp_arg['DeliverySurname'] = substr($purchase_data['post_data']['edd_last'], 0, 20);
            $sp_arg['DeliveryFirstnames'] = substr($purchase_data['post_data']['edd_first'], 0, 20);
            $sp_arg['DeliveryAddress1'] = substr($purchase_data['post_data']['card_address'], 0, 100);
            $sp_arg['DeliveryAddress2'] = substr($purchase_data['post_data']['card_address_2'], 0, 100);
            $sp_arg['DeliveryCity'] = substr($purchase_data['post_data']['card_city'], 0, 40);
            if ($purchase_data['post_data']['billing_country'] == 'US') {
                $sp_arg['DeliveryState'] = $purchase_data['post_data']['card_state'];
            } else {
                $sp_arg['DeliveryState'] = '';
            }
            $sp_arg['DeliveryPostCode'] = substr($purchase_data['post_data']['card_zip'], 0, 10);
            $sp_arg['DeliveryCountry'] = $purchase_data['post_data']['billing_country'];
            //$sp_arg['DeliveryPhone'] 		= substr($purchase_data['post_data']['edd_phone'], 0, 20);
            $sp_arg['CardHolder'] = $purchase_data['post_data']['card_name'];
            $sp_arg['CardNumber'] = $purchase_data['post_data']['card_number'];
            $sp_arg['StartDate'] = '';
            $sp_arg['ExpiryDate'] = sprintf("%02d", $purchase_data['post_data']['card_exp_month']) . date("y", strtotime("01/01/" . $purchase_data['post_data']['card_exp_year']));
            $sp_arg['CV2'] = $purchase_data['post_data']['card_cvc'];
            $sp_arg['CardType'] = $purchase_data['post_data']['card_type'];
            $sp_arg['VPSProtocol'] = "3.00";
            $sp_arg['Vendor'] = $edd_options['sagepay_direct_vendor_name'];
            $sp_arg['Description'] = sprintf(__('Order #%s', 'sagepay_direct_patsatech'), $payment);
            $sp_arg['Currency'] = edd_get_currency();
            $sp_arg['TxType'] = $edd_options['sagepay_direct_transtype'];
            $sp_arg['VendorTxCode'] = $orderid;
            $post_values = "";
            foreach ($sp_arg as $key => $value) {
                $post_values .= "{$key}=" . urlencode($value) . "&";
            }
            $post_values = rtrim($post_values, "& ");
            if ($edd_options['sagepay_direct_mode'] == 'test') {
                $gateway_url = 'https://test.sagepay.com/gateway/service/vspdirect-register.vsp';
            } else {
                if ($edd_options['sagepay_direct_mode'] == 'live') {
                    $gateway_url = 'https://live.sagepay.com/gateway/service/vspdirect-register.vsp';
                }
            }
            $response = wp_remote_post($gateway_url, array('body' => $post_values, 'method' => 'POST', 'sslverify' => FALSE));
            EDD()->session->set('sagepay_vtc', $orderid);
            EDD()->session->set('sagepay_oid', $payment);
            if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) {
                $resp = array();
                $lines = preg_split('/\\r\\n|\\r|\\n/', $response['body']);
                foreach ($lines as $line) {
                    $key_value = preg_split('/=/', $line, 2);
                    if (count($key_value) > 1) {
                        $resp[trim($key_value[0])] = trim($key_value[1]);
                    }
                }
                if ($resp['Status'] == "OK" || $resp['Status'] == "REGISTERED" || $resp['Status'] == "AUTHENTICATED") {
                    edd_update_payment_status($payment, 'publish');
                    edd_set_payment_transaction_id($payment, $resp['VPSTxId']);
                    edd_empty_cart();
                    edd_send_to_success_page();
                } else {
                    if ($resp['Status'] == "3DAUTH") {
                        if ($resp['3DSecureStatus'] == 'OK') {
                            if (isset($resp['ACSURL']) && isset($resp['MD'])) {
                                $array = array('PaReq' => $resp['PAReq'], 'MD' => $resp['MD'], 'TermUrl' => trailingslashit(home_url()) . '?sagepay_direct=ipn');
                                $sagepay_arg_array = array();
                                foreach ($array as $key => $value) {
                                    $sagepay_arg_array[] = '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_attr($value) . '" />';
                                }
                                echo '<form action="' . $resp['ACSURL'] . '" method="post" name="sagepay_direct_3dsecure_form" >
									' . implode('', $sagepay_arg_array) . '
									</form>
									<b> Please wait while you are being redirected.</b>
									<script type="text/javascript" event="onload">
											document.sagepay_direct_3dsecure_form.submit();
									</script>';
                            }
                        }
                    } else {
                        if (isset($resp['StatusDetail'])) {
                            edd_set_error('error_tranasction_failed', __('Transaction Failed. ' . $resp['StatusDetail'], 'sagepay_direct_patsatech'));
                            edd_send_back_to_checkout('?payment-mode=sagepay_direct');
                        } else {
                            edd_set_error('error_tranasction_failed', __('Transaction Failed with ' . $resp['Status'] . ' status for Unknown Reason.', 'sagepay_direct_patsatech'));
                            edd_send_back_to_checkout('?payment-mode=sagepay_direct');
                        }
                    }
                }
            } else {
                edd_set_error('error_tranasction_failed', __('Gateway Error. Please Notify the Store Owner about this error.', 'sagepay_direct_patsatech'));
                edd_send_back_to_checkout('?payment-mode=sagepay_direct');
            }
        }
    }
}
 public function process_payment($purchase_data)
 {
     if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'edd-gateway')) {
         wp_die(__('Nonce verification has failed', GOURLEDD), __('Error', GOURLEDD), array('response' => 403));
     }
     $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'status' => 'pending');
     // Record the pending payment
     $payment_id = edd_insert_payment($payment_data);
     if ($payment_id) {
         // Save Log
         $userID = edd_get_payment_user_id($payment_id);
         $user = !$userID ? __('Guest', GOURLEDD) : "<a href='" . admin_url("user-edit.php?user_id=" . $userID) . "'>user" . $userID . "</a>";
         edd_insert_payment_note($payment_id, sprintf(__('Order Created by %s. <br/>Awaiting cryptocurrency payment ...', GOURLEDD), $user) . ' <br/>');
         // Forward to payment page
         edd_empty_cart();
         edd_send_to_success_page();
     } else {
         edd_record_gateway_error(__('Payment Error', GOURLEDD), sprintf(__('Payment creation failed while processing Bitcoin/Altcoin purchase. Payment data: %s', GOURLEDD), json_encode($payment_data)), $payment);
         // If errors are present, send the user back to the purchase page so they can be corrected
         edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
     }
     return true;
 }
 /**
  * Process Shmart Purchase
  * @global $edd_options Array of all the EDD Options
  * @param array   $purchase_data Purchase Data
  * @return void
  */
 function process_shmart_purchase($purchase_data)
 {
     global $edd_options;
     if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'edd-gateway')) {
         wp_die(__('Nonce verification has failed', 'edd-shmart'), __('Error', 'edd-shmart'), array('response' => 403));
     }
     // Collect payment data
     $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'gateway' => 'shmart', 'status' => 'pending');
     // Add contact number if user is logged in.
     if (is_user_logged_in()) {
         $user_ID = get_current_user_id();
         // Add contact number in user meta.
         update_user_meta($user_ID, '_edd_user_contact_info', $purchase_data['post_data']['contact_number']);
     }
     // Record the pending payment
     $payment = edd_insert_payment($payment_data);
     // Check payment
     if (!$payment) {
         // Record the error
         edd_record_gateway_error(__('Payment Error', 'edd-shmart'), sprintf(__('Payment creation failed before sending buyer to Shmart. Payment data: %s', 'edd-shmart'), json_encode($payment_data)), $payment);
         // Problems? send back
         edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
     } else {
         // Only send to Shmart if the pending payment is created successfully
         //$listener_url = add_query_arg( 'edd-listener', 'SHMART_RESPONSE', home_url( 'index.php' ) );
         // Get the success url
         $listener_url = add_query_arg(array('edd-listener' => 'SHMART_RESPONSE', 'payment-id' => $payment), home_url('index.php'));
         // Get the Shmart redirect uri
         $shmart_redirect = trailingslashit($this->get_shmart_redirect());
         // Merchant ID.
         $merchant_id = $edd_options['shmart_merchant_id'];
         // Generate merchant ref ID.
         $merchant_refID = $this->generate_merchant_ref_ID();
         // Checksum Method.
         $checksum_method = 'MD5';
         /* Do currency conversion. */
         $amount = $this->do_currency_conversion($purchase_data['price']);
         // Round up final amount and convert amount into paisa.
         $amount = ceil($amount) * 100;
         //Get server IP address.
         $ip_address = gethostbyname($_SERVER['SERVER_NAME']);
         // String to generate checksum.
         $checksum_string = $edd_options['shmart_secret_key'] . $merchant_id . '|' . $edd_options['shmart_apikey'] . '|' . $ip_address . '|' . $merchant_refID . '|' . 'INR' . '|' . $amount . '|' . $checksum_method . '|' . 1;
         // Generate checksum.
         $checksum = md5($checksum_string);
         // Setup Shamrt arguments
         $shamrt_args = array('apikey' => $edd_options['shmart_apikey'], 'currency_code' => 'INR', 'amount' => $amount, 'merchant_refID' => $merchant_refID, 'merchant_id' => $merchant_id, 'checksum_method' => $checksum_method, 'checksum' => $checksum, 'ip_address' => $ip_address, 'email' => $purchase_data['user_email'], 'mobileNo' => $purchase_data['post_data']['contact_number'], 'f_name' => $purchase_data['user_info']['first_name'], 'addr' => $purchase_data['user_info']['address']['line1'] . ', ' . $purchase_data['user_info']['address']['line2'], 'city' => $purchase_data['user_info']['address']['city'], 'state' => $purchase_data['user_info']['address']['state'], 'zipcode' => $purchase_data['user_info']['address']['zip'], 'country' => $purchase_data['user_info']['address']['country'], 'show_shipping_addr' => 0, 'rurl' => get_permalink($edd_options['success_page']), 'furl' => edd_get_failed_transaction_uri('?payment-id=' . $payment), 'surl' => $listener_url, 'authorize_user' => 1);
         $shamrt_args = apply_filters('edd_shmart_redirect_args', $shamrt_args, $purchase_data);
         echo '<form action="' . $shmart_redirect . '" method="POST" name="shmartForm">';
         foreach ($shamrt_args as $arg => $arg_value) {
             echo '<input type="hidden" name="' . $arg . '" value="' . $arg_value . '">';
         }
         echo '</form>
               <script language="JavaScript">
                    document.shmartForm.submit();
               </script>';
         die;
     }
 }
function edd_veritrans_payment($purchase_data)
{
    global $edd_options;
    require_once plugin_dir_path(__FILE__) . '/lib/Veritrans.php';
    /**********************************
     * set transaction mode
     **********************************/
    if (edd_is_test_mode()) {
        // set test credentials here
        Veritrans_Config::$isProduction = false;
        Veritrans_Config::$serverKey = $edd_options['vt_sandbox_api_key'];
    } else {
        // set live credentials here
        Veritrans_Config::$isProduction = true;
        Veritrans_Config::$serverKey = $edd_options['vt_production_api_key'];
    }
    // check for any stored errors
    $errors = edd_get_errors();
    if (!$errors) {
        $purchase_summary = edd_get_purchase_summary($purchase_data);
        // error_log('purchase data: '.print_r($purchase_data,true)); //debugan
        // error_log('purchase summary: '.print_r($purchase_summary,true)); //debugan
        // error_log('plugin_dir_path : '.plugin_dir_path(__FILE__)); //debugan
        /**********************************
         * setup the payment details
         **********************************/
        // error_log(json_encode($purchase_data, true));
        $payment = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => $edd_options['currency'], 'downloads' => $purchase_data['downloads'], 'cart_details' => $purchase_data['cart_details'], 'user_info' => $purchase_data['user_info'], 'status' => 'pending');
        // record the pending payment
        $payment = edd_insert_payment($payment);
        // create item
        $transaction_details = array();
        foreach ($purchase_data['cart_details'] as $item) {
            $vt_item = array('id' => $item['id'], 'price' => $item['price'], 'quantity' => $item['quantity'], 'name' => $item['name']);
            array_push($transaction_details, $vt_item);
        }
        $vt_params = array('transaction_details' => array('order_id' => $payment, 'gross_amount' => $purchase_data['price']), 'customer_details' => array('first_name' => $purchase_data['user_info']['first_name'], 'last_name' => $purchase_data['user_info']['last_name'], 'email' => $purchase_data['user_info']['email'], 'billing_address' => array('first_name' => $purchase_data['user_info']['first_name'], 'last_name' => $purchase_data['user_info']['last_name'])), 'item_details' => $transaction_details);
        //get enabled payment opts from backend
        $enabled_payments = edd_get_vtpayment_ops();
        if (!empty($enabled_payments)) {
            $vt_params['vtweb']['enabled_payments'] = $enabled_payments;
        }
        // error_log('vt_3ds '.$edd_options['vt_3ds']); //debugan
        // get rid of cart contents
        edd_empty_cart();
        // Redirect to veritrans
        // error_log('vt_params: '.print_r($vt_params,true)); //debugan
        wp_redirect(Veritrans_Vtweb::getRedirectionUrl($vt_params));
        exit;
    } else {
        $fail = true;
        // errors were detected
    }
    if ($fail !== false) {
        // if errors are present, send the user back to the purchase page so they can be corrected
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    }
}
 /**
  * The $purchase_data array consists of the following data:
  *
  * $purchase_data = array(
  *   'downloads'    => array of download IDs,
  *   'tax'          => taxed amount on shopping cart
  *   'subtotal'     => total price before tax
  *   'price'        => total price of cart contents after taxes,
  *   'purchase_key' => Random key
  *   'user_email'   => $user_email,
  *   'date'         => date( 'Y-m-d H:i:s' ),
  *   'user_id'      => $user_id,
  *   'post_data'    => $_POST,
  *   'user_info'    => array of user's information and used discount code
  *   'cart_details' => array of cart details,
  * );
  */
 public function process_purchase($purchase_data)
 {
     $config_id = edd_get_option($this->id . '_config_id');
     // Collect payment data
     $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'gateway' => $this->id, 'status' => 'pending');
     // Record the pending payment
     $payment_id = edd_insert_payment($payment_data);
     // Check payment
     if (!$payment_id) {
         // Log error
         edd_record_gateway_error(__('Payment Error', 'pronamic_ideal'), sprintf(__('Payment creation failed before sending buyer to the payment provider. Payment data: %s', 'pronamic_ideal'), json_encode($payment_data)), $payment_id);
         edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
     } else {
         $data = new Pronamic_WP_Pay_Extensions_EDD_PaymentData($payment_id, $payment_data);
         $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id);
         if ($gateway) {
             // Start
             $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data, $this->payment_method);
             $error = $gateway->get_error();
             if (is_wp_error($error)) {
                 edd_record_gateway_error(__('Payment Error', 'pronamic_ideal'), sprintf(__('Payment creation failed before sending buyer to the payment provider. Payment data: %s', 'pronamic_ideal'), json_encode($payment_data)), $payment_id);
                 edd_set_error('pronamic_pay_error', Pronamic_WP_Pay_Plugin::get_default_error_message());
                 foreach ($error->get_error_messages() as $i => $message) {
                     edd_set_error('pronamic_pay_error_' . $i, $message);
                 }
                 edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
             } else {
                 // Transaction ID
                 // @see https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/2.3/includes/payments/functions.php#L1400-L1416
                 edd_set_payment_transaction_id($payment_id, $payment->get_transaction_id());
                 // Payment note
                 $payment_link = add_query_arg(array('post' => $payment->get_id(), 'action' => 'edit'), admin_url('post.php'));
                 $note = sprintf(__('Payment %s pending.', 'pronamic_ideal'), sprintf('<a href="%s">#%s</a>', $payment_link, $payment->get_id()));
                 edd_insert_payment_note($payment_id, $note);
                 $gateway->redirect($payment);
                 exit;
             }
         } else {
             edd_set_error('pronamic_pay_error', Pronamic_WP_Pay_Plugin::get_default_error_message());
             edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
         }
     }
 }
 /**
  * Create sample purchase data for your EDD site
  *
  * ## OPTIONS
  *
  * --number: The number of purchases to create
  * --status=<status>: The status to create purchases as
  * --id=<product_id>: A specific product to create purchase data for
  * --price_id=<price_id>: A price ID of the specified product
  *
  * ## EXAMPLES
  *
  * wp edd payments create --number=10 --status=completed
  * wp edd payments create --number=10 --id=103
  */
 public function payments($args, $assoc_args)
 {
     $error = false;
     // At some point we'll likely add another action for payments
     if (!isset($args) || count($args) == 0) {
         $error = __('No action specified, did you mean', 'easy-digital-downloads');
     } elseif (isset($args) && !in_array('create', $args)) {
         $error = __('Invalid action specified, did you mean', 'easy-digital-downloads');
     }
     if ($error) {
         foreach ($assoc_args as $key => $value) {
             $query .= ' --' . $key . '=' . $value;
         }
         WP_CLI::error(sprintf($error . ' %s?', 'wp edd payments create' . $query));
         return;
     }
     // Setup some defaults
     $number = 1;
     $status = 'complete';
     $id = false;
     $price_id = false;
     if (count($assoc_args) > 0) {
         $number = array_key_exists('number', $assoc_args) ? absint($assoc_args['number']) : $number;
         $id = array_key_exists('id', $assoc_args) ? absint($assoc_args['id']) : $id;
         $price_id = array_key_exists('price_id', $assoc_args) ? absint($assoc_args['id']) : false;
         $tax = array_key_exists('tax', $assoc_args) ? floatval($assoc_args['tax']) : 0;
         $email = array_key_exists('email', $assoc_args) ? sanitize_email($assoc_args['email']) : '*****@*****.**';
         $fname = array_key_exists('fname', $assoc_args) ? sanitize_text_field($assoc_args['fname']) : 'Pippin';
         $lname = array_key_exists('lname', $assoc_args) ? sanitize_text_field($assoc_args['lname']) : 'Williamson';
         // Status requires a bit more validation
         if (array_key_exists('status', $assoc_args)) {
             $stati = array('publish', 'complete', 'pending', 'refunded', 'revoked', 'failed', 'abandoned', 'preapproval', 'cancelled');
             if (in_array($assoc_args['status'], $stati)) {
                 $status = $assoc_args['status'] == 'complete' ? 'publish' : $assoc_args['status'];
             } else {
                 WP_CLI::warning(sprintf(__("Invalid status '%s', defaulting to 'complete'", 'easy-digital-downloads'), $assoc_args['status']));
             }
         }
     }
     // Build the user info array
     $user_info = array('id' => 0, 'email' => $email, 'first_name' => $fname, 'last_name' => $lname, 'discount' => 'none');
     for ($i = 0; $i < $number; $i++) {
         $products = array();
         $total = 0;
         // No specified product
         if (!$id) {
             $products = get_posts(array('post_type' => 'download', 'orderby' => 'rand', 'order' => 'ASC', 'posts_per_page' => 1));
         } else {
             $product = get_post($id);
             if ($product->post_type != 'download') {
                 WP_CLI::error(__('Specified ID is not a product', 'easy-digital-downloads'));
                 return;
             }
             $products[] = $product;
         }
         $cart_details = array();
         // Create the purchases
         foreach ($products as $key => $download) {
             if (!is_a($download, 'WP_Post')) {
                 continue;
             }
             $options = array();
             $final_downloads = array();
             // Deal with variable pricing
             if (edd_has_variable_prices($download->ID)) {
                 $prices = edd_get_variable_prices($download->ID);
                 if (false === $price_id || !array_key_exists($price_id, (array) $prices)) {
                     $price_id = rand(0, count($prices) - 1);
                 }
                 $item_price = $prices[$price_id]['amount'];
                 $options['price_id'] = $price_id;
             } else {
                 $item_price = edd_get_download_price($download->ID);
             }
             $item_number = array('id' => $download->ID, 'quantity' => 1, 'options' => $options);
             $cart_details[$key] = array('name' => $download->post_title, 'id' => $download->ID, 'item_number' => $item_number, 'item_price' => edd_sanitize_amount($item_price), 'subtotal' => edd_sanitize_amount($item_price), 'price' => edd_sanitize_amount($item_price), 'quantity' => 1, 'discount' => 0, 'tax' => $tax);
             $final_downloads[$key] = $item_number;
             $total += $item_price;
         }
         $purchase_data = array('price' => edd_sanitize_amount($total), 'tax' => 0, 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $email, 'user_info' => $user_info, 'currency' => edd_get_currency(), 'downloads' => $final_downloads, 'cart_details' => $cart_details, 'status' => 'pending');
         $payment_id = edd_insert_payment($purchase_data);
         remove_action('edd_complete_purchase', 'edd_trigger_purchase_receipt', 999);
         if ($status != 'pending') {
             edd_update_payment_status($payment_id, $status);
         }
     }
     WP_CLI::success(sprintf(__('Created %s payments', 'easy-digital-downloads'), $number));
     return;
 }
Example #26
0
function mondca_process_payment($purchase_data)
{
    global $edd_options;
    // check there is a gateway name
    if (!isset($purchase_data['post_data']['edd-gateway'])) {
        return;
    }
    // collect payment data
    $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'gateway' => 'mondca', 'status' => 'pending');
    if (!mondca_is_credit_card_number($purchase_data['post_data']['card_number'])) {
        edd_set_error('invalid_card_number', __('Credit Card Number is not valid.', 'mondca_patsatech'));
    }
    if (!mondca_is_correct_expire_date(date("y", strtotime($purchase_data['post_data']['card_exp_month'])), $purchase_data['post_data']['card_exp_year'])) {
        edd_set_error('invalid_card_expiry', __('Card Expire Date is not valid.', 'mondca_patsatech'));
    }
    if (!$purchase_data['post_data']['card_cvc']) {
        edd_set_error('invalid_card_cvc', __('Card CVV is not entered.', 'mondca_patsatech'));
    }
    if (!$purchase_data['post_data']['card_name']) {
        edd_set_error('invalid_card_name', __('CardHolder Name is not entered.', 'mondca_patsatech'));
    }
    if (!$purchase_data['post_data']['card_address']) {
        edd_set_error('invalid_card_address', __('Billing Address is not entered.', 'mondca_patsatech'));
    }
    if (!$purchase_data['post_data']['card_zip']) {
        edd_set_error('invalid_card_zip', __('Post Code is not entered.', 'mondca_patsatech'));
    }
    if (!$purchase_data['post_data']['card_state']) {
        edd_set_error('invalid_card_state', __('State is not entered.', 'mondca_patsatech'));
    }
    if (!$purchase_data['post_data']['card_city']) {
        edd_set_error('invalid_card_city', __('City is not entered.', 'mondca_patsatech'));
    }
    if (!$purchase_data['post_data']['edd_first']) {
        edd_set_error('invalid_edd_first', __('First Name is not entered.', 'mondca_patsatech'));
    }
    if (!$purchase_data['post_data']['edd_last']) {
        edd_set_error('invalid_edd_last', __('Last Name is not entered.', 'mondca_patsatech'));
    }
    $errors = edd_get_errors();
    if ($errors) {
        // problems? send back
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    } else {
        // record the pending payment
        $payment = edd_insert_payment($payment_data);
        // check payment
        if (!$payment) {
            // problems? send back
            edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
        } else {
            $store_id = $edd_options['mondca_storeid'];
            $api_token = $edd_options['mondca_apitoken'];
            $type = 'purchase';
            //$cust_id = $order->order_key;
            $amount = number_format($purchase_data['price'], 2, '.', '');
            $pan = $purchase_data['post_data']['card_number'];
            $cavv = $purchase_data['post_data']['card_cvc'];
            $expiry_date = substr($purchase_data['post_data']['card_exp_year'], -2) . sprintf("%02s", $purchase_data['post_data']['card_exp_month']);
            $crypt = '7';
            $status_check = 'false';
            $stamp = date("YdmHisB");
            $orderid = $stamp . '|' . $payment;
            /***************** Transactional Associative Array ********************/
            //$arr=explode("|",$teststring);
            $txnArray = array('type' => $type, 'order_id' => $orderid, 'cust_id' => '', 'amount' => $amount, 'pan' => $pan, 'expdate' => $expiry_date, 'cavv' => $cavv);
            /********************** Transaction Object ****************************/
            $mpgTxn = new mpgTransaction($txnArray);
            /************************ Request Object ******************************/
            $mpgRequest = new mpgRequest($mpgTxn);
            /*********************** HTTPSPost Object ****************************/
            $mpgHttpPost = new mpgHttpsPost($store_id, $api_token, $mpgRequest);
            /*************************** Response *********************************/
            $mpgResponse = $mpgHttpPost->getMpgResponse();
            $txnno = $mpgResponse->getTxnNumber();
            $receipt = explode("|", $mpgResponse->getReceiptId());
            $respcode = $mpgResponse->getResponseCode();
            $refnum = $mpgResponse->getReferenceNum();
            $auth = $mpgResponse->getAuthCode();
            $mess = $mpgResponse->getMessage();
            if ($respcode < '50' && $respcode > '0') {
                edd_update_payment_status($payment, 'publish');
                edd_insert_payment_note($payment, sprintf(__('Moneris CA Payment %s. The Transaction Id is %s', 'mondca_patsatech'), $mess, $txnno));
                edd_empty_cart();
                edd_send_to_success_page();
            } else {
                edd_insert_payment_note($payment, sprintf(__('Transaction Error. Message : %s', 'mondca_patsatech'), $mess));
                edd_set_error('error_tranasction_failed', sprintf(__('Transaction Error. Message : %s', 'mondca_patsatech'), $mess));
                edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
            }
        }
    }
}
/**
 * Process PayPal Purchase
 *
 * @since 1.0
 * @param array   $purchase_data Purchase Data
 * @return void
 */
function edd_process_paypal_purchase($purchase_data)
{
    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'edd-gateway')) {
        wp_die(__('Nonce verification has failed', 'edd'), __('Error', 'edd'), array('response' => 403));
    }
    // Collect payment data
    $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'gateway' => 'paypal', 'status' => !empty($purchase_data['buy_now']) ? 'private' : 'pending');
    // Record the pending payment
    $payment = edd_insert_payment($payment_data);
    // Check payment
    if (!$payment) {
        // Record the error
        edd_record_gateway_error(__('Payment Error', 'edd'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'edd'), json_encode($payment_data)), $payment);
        // Problems? send back
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    } else {
        // Only send to PayPal if the pending payment is created successfully
        $listener_url = add_query_arg('edd-listener', 'IPN', home_url('index.php'));
        // Get the success url
        $return_url = add_query_arg(array('payment-confirmation' => 'paypal', 'payment-id' => $payment), get_permalink(edd_get_option('success_page', false)));
        // Get the PayPal redirect uri
        $paypal_redirect = trailingslashit(edd_get_paypal_redirect()) . '?';
        // Setup PayPal arguments
        $paypal_args = array('business' => edd_get_option('paypal_email', false), 'email' => $purchase_data['user_email'], 'first_name' => $purchase_data['user_info']['first_name'], 'last_name' => $purchase_data['user_info']['last_name'], 'invoice' => $purchase_data['purchase_key'], 'no_shipping' => '1', 'shipping' => '0', 'no_note' => '1', 'currency_code' => edd_get_currency(), 'charset' => get_bloginfo('charset'), 'custom' => $payment, 'rm' => '2', 'return' => $return_url, 'cancel_return' => edd_get_failed_transaction_uri('?payment-id=' . $payment), 'notify_url' => $listener_url, 'page_style' => edd_get_paypal_page_style(), 'cbt' => get_bloginfo('name'), 'bn' => 'EasyDigitalDownloads_SP');
        if (!empty($purchase_data['user_info']['address'])) {
            $paypal_args['address1'] = $purchase_data['user_info']['address']['line1'];
            $paypal_args['address2'] = $purchase_data['user_info']['address']['line2'];
            $paypal_args['city'] = $purchase_data['user_info']['address']['city'];
            $paypal_args['country'] = $purchase_data['user_info']['address']['country'];
        }
        $paypal_extra_args = array('cmd' => '_cart', 'upload' => '1');
        $paypal_args = array_merge($paypal_extra_args, $paypal_args);
        // Add cart items
        $i = 1;
        foreach ($purchase_data['cart_details'] as $item) {
            $item_amount = round($item['subtotal'] / $item['quantity'] - $item['discount'] / $item['quantity'], 2);
            if ($item_amount <= 0) {
                $item_amount = 0;
            }
            $paypal_args['item_name_' . $i] = stripslashes_deep(html_entity_decode(edd_get_cart_item_name($item), ENT_COMPAT, 'UTF-8'));
            $paypal_args['quantity_' . $i] = $item['quantity'];
            $paypal_args['amount_' . $i] = $item_amount;
            if (edd_use_skus()) {
                $paypal_args['item_number_' . $i] = edd_get_download_sku($item['id']);
            }
            $i++;
        }
        // Calculate discount
        $discounted_amount = 0.0;
        if (!empty($purchase_data['fees'])) {
            $i = empty($i) ? 1 : $i;
            foreach ($purchase_data['fees'] as $fee) {
                if (floatval($fee['amount']) > '0') {
                    // this is a positive fee
                    $paypal_args['item_name_' . $i] = stripslashes_deep(html_entity_decode(wp_strip_all_tags($fee['label']), ENT_COMPAT, 'UTF-8'));
                    $paypal_args['quantity_' . $i] = '1';
                    $paypal_args['amount_' . $i] = edd_sanitize_amount($fee['amount']);
                    $i++;
                } else {
                    // This is a negative fee (discount)
                    $discounted_amount += abs($fee['amount']);
                }
            }
        }
        if ($discounted_amount > '0') {
            $paypal_args['discount_amount_cart'] = edd_sanitize_amount($discounted_amount);
        }
        // Add taxes to the cart
        if (edd_use_taxes()) {
            $paypal_args['tax_cart'] = edd_sanitize_amount($purchase_data['tax']);
        }
        $paypal_args = apply_filters('edd_paypal_redirect_args', $paypal_args, $purchase_data);
        // Build query
        $paypal_redirect .= http_build_query($paypal_args);
        // Fix for some sites that encode the entities
        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
        // Get rid of cart contents
        edd_empty_cart();
        // Redirect to PayPal
        wp_redirect($paypal_redirect);
        exit;
    }
}
 /**
  * process_payment function.
  *
  * Submit payment and handle response
  *
  * @access public
  */
 public function process_payment($purchase_data)
 {
     //edd_options contains the values of the admin settings
     global $edd_options;
     if (edd_is_test_mode()) {
         $paystack_public = $edd_options['test_public_key'];
         $paystack_secret = $edd_options['test_secret_key'];
     } else {
         $paystack_public = $edd_options['live_public_key'];
         $paystack_secret = $edd_options['live_secret_key'];
     }
     //txcode POSTed from payment form
     $txcode = isset($_POST['txcode']) ? $_POST['txcode'] : null;
     /**
      * check for checkout fields errors
      *
      */
     // check if there is a gateway name
     if (!isset($purchase_data['post_data']['edd-gateway'])) {
         return;
     }
     // get EDD errors
     $errors = edd_get_errors();
     // Paystack errors
     $paystack_error = null;
     /**
      * end checkout fields error checks
      */
     // if no errors
     if (!$errors) {
         // record purchase summary
         $summary = edd_get_purchase_summary($purchase_data, false);
         // cart quantity
         $quantity = edd_get_cart_quantity();
         /**
          * setup the payment data
          */
         $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => $edd_options['currency'], 'downloads' => $purchase_data['downloads'], 'cart_details' => $purchase_data['cart_details'], 'user_info' => $purchase_data['user_info'], 'status' => 'pending');
         // record the pending payment
         $payment = edd_insert_payment($payment_data);
         $order_id = $payment;
         if (!$payment) {
             // Record the error
             edd_record_gateway_error(__('Payment Error', 'po_paystack'), sprintf(__('Payment creation failed before loading Paystack. Payment data: %s', 'po_paystack'), json_encode($payment_data)), $payment);
             // Problems? send back
             edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
         } else {
             if (!$order_id || !$paystack_public) {
                 edd_record_gateway_error(__('Invalid transaction', 'po_paystack'), sprintf(__('Invalid transaction; possible hack attempt. Payment data: %s', 'po_paystack'), json_encode($payment_data)), $payment);
                 edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
             }
             if (!$txcode) {
                 $error = "Error! An invalid transaction code was reported.";
                 edd_update_payment_status($order_id, 'failed');
                 throw new Exception(__($error));
             } else {
                 $amount = $payment_data['price'] * 100;
                 //convert to kobo
                 if (intval($amount) < 100) {
                     $error = "Invalid transaction. Paystack cannot process orders under 100 kobo in value. Transaction code: " . $txcode;
                     edd_update_payment_status($order_id, 'failed');
                     throw new Exception(__($error));
                 }
                 $email = $payment_data['user_email'];
                 require_once dirname(__FILE__) . '/paystack-class/Paystack.php';
                 // Create the library object
                 $paystack = new Paystack($paystack_secret);
                 list($headers, $body, $code) = $paystack->transaction->verify(['reference' => $txcode]);
                 $resp = $body;
                 if (array_key_exists("status", $resp) && !$resp["status"]) {
                     $error = "Failed with message from Paystack: " . $resp["message"];
                     edd_insert_payment_note($order_id, __($error));
                     edd_update_payment_status($order_id, 'failed');
                     throw new Exception(__($error));
                 } elseif ($resp["data"]["customer"]["email"] !== $email) {
                     $error = "Invalid customer email associated with Transaction code:" . $txcode . " and Paystack reference: " . $resp["data"]['reference'] . ". Possible hack attempt.";
                     edd_insert_payment_note($order_id, __($error));
                     edd_update_payment_status($order_id, 'failed');
                     throw new Exception(__($error));
                 } else {
                     // Authcode and Authdesc. To be used in future version, for recurrent billing
                     $authcode = $resp["data"]["authorization"]["authorization_code"];
                     $authdesc = $resp["data"]["authorization"]["description"];
                     $paystackref = $resp["data"]["reference"];
                     // Complete the order. once a transaction is successful, set the purchase status to complete
                     edd_update_payment_status($payment, 'complete');
                     // record transaction ID, or any other notes you need
                     edd_insert_payment_note($payment, "Paystack.co payment completed (using " . strtoupper($authdesc) . " and Transaction code:" . $txcode . ") with Paystack reference:" . $paystackref);
                     // go to the success page
                     edd_send_to_success_page();
                 }
             }
         }
     } else {
         // errors present
         $fail = true;
     }
     if ($fail !== false) {
         // if errors are present, send the user back to the purchase page so they can be corrected
         edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
     }
 }
 /**
  * Process the credit card form
  *
  * @param array $purchaseDatas
  */
 public function processPayboxPurchase($purchaseDatas)
 {
     $this->purchaseDatas = $purchaseDatas;
     $this->gateway = $purchaseDatas['post_data']['edd-gateway'];
     $paymentDatas = array('price' => $purchaseDatas['price'], 'date' => $purchaseDatas['date'], 'user_email' => $purchaseDatas['user_email'], 'purchase_key' => $purchaseDatas['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchaseDatas['downloads'], 'user_info' => $purchaseDatas['user_info'], 'cart_details' => $purchaseDatas['cart_details'], 'gateway' => 'paybox', 'status' => 'pending');
     // Record the pending payment
     $this->payment = edd_insert_payment($paymentDatas);
     $orderTotal = $purchaseDatas['price'];
     $id = $purchaseDatas['user_info']['id'] . intval($purchaseDatas['subtotal']);
     $cardNumber = $purchaseDatas['card_info']['card_number'];
     $cvv = $purchaseDatas['card_info']['card_cvc'];
     $monthExpire = $purchaseDatas['card_info']['card_exp_month'];
     $yearExpire = $purchaseDatas['card_info']['card_exp_year'];
     $settings = $this->getSettings();
     $url = $settings['preprod'] ? $settings['url_preprod'] : $settings['url_prod'];
     $fields = array('DATEQ' => date('Ydm'), 'TYPE' => '00001', 'NUMQUESTION' => time(), 'MONTANT' => intval($orderTotal), 'SITE' => $settings['site'], 'RANG' => $settings['rang'], 'REFERENCE' => 'test', 'VERSION' => $settings['version'], 'CLE' => $settings['key'], 'IDENTIFIANT' => $settings['id'], 'DEVISE' => '978', 'PORTEUR' => $cardNumber, 'DATEVAL' => str_pad($monthExpire, 2, '0', STR_PAD_LEFT) . substr($yearExpire, 2, 4), 'CVV' => $cvv, 'ACTIVITE' => '024', 'ARCHIVAGE' => 'AXZ130968CT2', 'DIFFERE' => '000', 'NUMAPPEL' => '', 'NUMTRANS' => '', 'AUTORISATION' => '', 'PAYS' => '');
     $this->performPayment($url, $fields);
 }
 // If Products & Cart array is not prepared ( loop broken in between ) then skip the order.
 if ($break_loop) {
     $temp_log_str = "\nWC Order could not be migrated ...\n";
     $log_str .= $temp_log_str;
     echo $temp_log_str;
     continue;
 }
 // If no products found in the order then also skip the order.
 if (empty($downloads) || empty($cart_details)) {
     $temp_log_str = "\nNo Products found. So order not migrated ...\n";
     $log_str .= $temp_log_str;
     echo $temp_log_str;
     continue;
 }
 $data = array('currency' => 'USD', 'downloads' => $downloads, 'cart_details' => $cart_details, 'price' => get_post_meta($order->id, '_order_total', true), 'purchase_key' => get_post_meta($order->id, '_order_key', true), 'user_info' => array('id' => $user_id, 'email' => $email, 'first_name' => get_post_meta($order->id, '_billing_first_name', true), 'last_name' => get_post_meta($order->id, '_billing_last_name', true), 'discount' => !empty($wc_coupon) && isset($wc_edd_coupon_map[$wc_coupon->id]) && !empty($wc_edd_coupon_map[$wc_coupon->id]) ? $wc_coupon->code : '', 'address' => array('line1' => get_post_meta($order->id, '_billing_address_1', true), 'line2' => get_post_meta($order->id, '_billing_address_2', true), 'city' => get_post_meta($order->id, '_billing_city', true), 'zip' => get_post_meta($order->id, '_billing_postcode', true), 'country' => get_post_meta($order->id, '_billing_country', true), 'state' => get_post_meta($order->id, '_billing_state', true))), 'user_id' => $user_id, 'user_email' => $email, 'status' => 'pending', 'parent' => $o->post_parent, 'post_date' => $o->post_date, 'gateway' => get_post_meta($order->id, '_payment_method', true));
 $payment_id = edd_insert_payment($data);
 remove_action('edd_update_payment_status', 'edd_trigger_purchase_receipt', 10);
 remove_action('edd_complete_purchase', 'edd_trigger_purchase_receipt', 999);
 edd_update_payment_status($payment_id, $status);
 $wc_edd_order_map[$o->ID] = $payment_id;
 $temp_log_str = "\nWC Order migrated ...\n";
 $log_str .= $temp_log_str;
 echo $temp_log_str;
 // Update relavent data.
 update_post_meta($payment_id, '_edd_payment_user_ip', get_post_meta($order->id, '_customer_ip_address', true));
 update_post_meta($payment_id, '_wc_order_key', get_post_meta($order->id, '_order_key', true));
 update_post_meta($payment_id, '_edd_payment_mode', 'live');
 update_post_meta($payment_id, '_edd_completed_date', get_post_meta($order->id, '_completed_date', true));
 update_post_meta($payment_id, '_wc_order_id', $o->ID);
 // Order Notes
 $args = array('post_id' => $order->id, 'approve' => 'approve');