Хотите добавить платежный шлюз PAYUMONEY в плагин Wordpress "Easy Digital Download"

Я хочу создать плагин для WordPress, который позволит легко и просто загружать платежный шлюз PAYUMONEY. Я сделал некоторое кодирование с помощью этой ссылки [1]: https://gist.github.com/amitabhaghosh197/788ef94f874ba6f4fdd0. Внесены некоторые изменения, но они не перенаправляют на payu, а просто переходят на страницу успешного платежа с ожидающим статусом оплаты. Мой код, как показано ниже

<?php
// registers the gateway
function pw_edd_register_gateway($gateways) {
$gateways['payu_money_gateway'] = array('admin_label' => 'PayU Money','checkout_label' => __('PayU Money', 'pw_edd'));
return $gateways;
}
add_filter('edd_payment_gateways', 'pw_edd_register_gateway');
function pw_edd_payu_money_gateway_cc_form() {
// register the action to remove default CC form
return;
}
add_action('edd_payu_money_gateway_cc_form',
'pw_edd_payu_money_gateway_cc_form');
// adds the settings to the Payment Gateways section
function pw_edd_add_settings($settings) {

$payu_settings = array(
    'header' =>array(
        'id' => 'payu_money_gateway_settings',
        'name' => '<strong>' . __( 'PayU Money Gateway Settings', 'pw_edd' ) . '</strong>',
        'desc' => __( 'Configure the gateway settings', 'pw_edd' ),
        'type' => 'header'
    ),
    'merchant_id' => array(
        'id' => 'live_api_key',
        'name' => __( 'Live Merchant Key', 'pw_edd' ),
        'desc' => __( 'Enter your live Merchant key, found in your gateway Account Settings', 'pw_edd' ),
        'type' => 'text',
        'size' => 'regular'
    ),
    'salt_key' => array(
        'id' => 'live_salt_key',
        'name' => __( 'Live Salt Key', 'pw_edd' ),
        'desc' => __( 'Enter your live Salt key, found in your gateway Account Settings', 'pw_edd' ),
        'type' => 'text',
        'size' => 'regular'
    ),
);

return array_merge($settings, $payu_settings);  
}
add_filter('edd_settings_gateways', 'pw_edd_add_settings');
// processes the payment
function pw_edd_process_payment($purchase_data) {

global $edd_options;

/**********************************
* 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_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);

if( $payment ) {

    /*$return_url = add_query_arg( 'payment-confirmation', 'payu', get_permalink( $edd_options['success_page'] ) );
    $purchase_summary = edd_get_purchase_summary($purchase_data);*/

    /**********************************
    * set transaction mode
    **********************************/

    if(edd_is_test_mode()) {
        // set test credentials here
        $payu_redirect = 'https://sandboxsecure.payu.in';
    } else {
        // set live credentials here
        $payu_redirect = 'https://secure.payu.in';
    }

    $succes_url         =  edd_send_to_success_page();
    $redirect_url       =  edd_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['edd-gateway'] );
    $txn_id             =  $purchase_data['purchase_key']; 
    $amount             =  $purchase_data['price'];
    $product_info       =  $purchase_data['cart_details'];
    $first_name         =  $purchase_data['user_info']['user_first'];
    $email              =  $purchase_data['user_email'];

    $str = "merchant_id|$txnid|$amount|$product_info|$first_name|$email|$txn_id||||||||||salt_key";
    $hash = strtolower(hash('sha512', $str));

    $payu_redirect_args =  array(
            'key'          => $payu_money_gateway_settings['merchant_id'],
            'txnid'        => $purchase_data['purchase_key'],
            'hash'         => $hash,
            'price'        => $purchase_data['price'],
            'email'        => $purchase_data['user_email'],
            'amount'       => $purchase_data['price'],
            'productinfo'  => $purchase_data['cart_details'],
            'firstname'    => $purchase_data['user_info']['user_first'],
            'lastname'     => $purchase_data['user_info']['user_last'],
            //'phone'        =>  $user_id-> _edd_user_phone,
            'surl'        => $succes_url,
            'furl'         => $redirect_url,
            //'curl'         => edd_send_to_success_page(),
            'service_provider' => 'payu_paisa'

    );

    $payu_redirect_args_array = array();
    $edd_remove_order = edd_remove_item_url( $cart_key, $post, $ajax );

   foreach($payu_redirect_args as $key => $value){
            $payu_redirect_args_array[] = "<input type='hidden' name='$key' value='$value'/>";
        }

        return '    <form action="'.$payu_redirect.'" method="post" id="payupaisa_payment_form">
            ' . implode('', $payu_redirect_args_array) . '

            <input type="submit" class="button-alt" id="submit_payupaisa_payment_form" value="'.__('Pay via PayU Money', 'edd').'" /> <a class="button cancel" href="'.$edd_remove_order.'">'.__('Cancel order &amp; restore cart', 'edd').'</a>
                <script type="text/javascript">
                jQuery(function(){
                jQuery("body").block({
                    message: "'.__('Thank you for your order. We are now redirecting you to Payment Gateway to make payment.', 'edd').'",
                    overlayCSS: {
                        background      : "#fff",
                        opacity         : 0.6
                    },
                    css: {
                        padding         : 20,
                        textAlign       : "center",
                        color           : "#555",
                        border          : "3px solid #aaa",
                        backgroundColor : "#fff",
                        cursor          : "wait",
                        lineHeight      : "32px"
                    }
                });
                jQuery("#submit_payupaisa_payment_form").click();});
                </script>
            </form>';


    /**********************************
    * check for errors here
    **********************************/

    /*
    // errors can be set like this
    if(!isset($_POST['card_number'])) {
        // error code followed by error message
        edd_set_error('empty_card', __('You must enter a card number', 'edd'));
    }
    */
    $payu_redirect = str_replace( '&amp;', '&', $payu_redirect );
    //var_dump(http_build_query($paypal_args)); exit;
    $payu_redirect .= http_build_query($payu_redirect_args);

    //var_dump(urldecode($paypal_redirect)); exit;

    // get rid of cart contents
    edd_empty_cart();

    // Redirect to paypal
    wp_redirect( $payu_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'] );
}
}
add_action('edd_gateway_payu_money_gateway', 'pw_edd_process_payment');

Пожалуйста, дайте некоторое предложение. Спасибо.

0 ответов

Другие вопросы по тегам