Exemplo n.º 1
0
    public static function dgButton($amount = '0.00', $description = '', $itemnumber = '101', $extra_array = null)
    {
        $extra = payment_prepare_custom($extra_array);
        $r = rand(0, 1000);
        $extra .= 'random,' . $r;
        $APIUSERNAME = payment_decrypt(osc_get_preference('paypal_api_username', 'payment'));
        $APIPASSWORD = payment_decrypt(osc_get_preference('paypal_api_password', 'payment'));
        $APISIGNATURE = payment_decrypt(osc_get_preference('paypal_api_signature', 'payment'));
        if (osc_get_preference('paypal_sandbox', 'payment') == 1) {
            $ENDPOINT = 'https://api-3t.sandbox.paypal.com/nvp';
        } else {
            $ENDPOINT = 'https://api-3t.paypal.com/nvp';
        }
        $VERSION = '65.1';
        // must be >= 65.1
        $REDIRECTURL = 'https://www.paypal.com/incontext?token=';
        if (osc_get_preference('paypal_sandbox', 'payment') == 1) {
            $REDIRECTURL = "https://www.sandbox.paypal.com/incontext?token=";
        }
        //Build the Credential String:
        $cred_str = 'USER='******'&PWD=' . $APIPASSWORD . '&SIGNATURE=' . $APISIGNATURE . '&VERSION=' . $VERSION;
        //For Testing this is hardcoded. You would want to set these variable values dynamically
        $nvp_str = "&METHOD=SetExpressCheckout" . '&RETURNURL=' . osc_base_url() . 'oc-content/plugins/' . osc_plugin_folder(__FILE__) . 'return.php?extra=' . $extra . '&CANCELURL=' . osc_base_url() . 'oc-content/plugins/' . osc_plugin_folder(__FILE__) . 'cancel.php?extra=' . $extra . '&PAYMENTREQUEST_0_CURRENCYCODE=' . osc_get_preference('currency', 'payment') . '&PAYMENTREQUEST_0_AMT=' . $amount . '&PAYMENTREQUEST_0_ITEMAMT=' . $amount . '&PAYMENTREQUEST_0_TAXAMT=0' . '&PAYMENTREQUEST_0_DESC=' . $description . '&PAYMENTREQUEST_0_PAYMENTACTION=Sale' . '&L_PAYMENTREQUEST_0_ITEMCATEGORY0=Digital' . '&L_PAYMENTREQUEST_0_NAME0=' . $description . '&L_PAYMENTREQUEST_0_NUMBER0=' . $itemnumber . '&L_PAYMENTREQUEST_0_QTY0=1' . '&L_PAYMENTREQUEST_0_TAXAMT0=0' . '&L_PAYMENTREQUEST_0_AMT0=' . $amount . '&L_PAYMENTREQUEST_0_DESC0=Download' . '&CUSTOM=' . $extra . '&useraction=commit';
        //combine the two strings and make the API Call
        $req_str = $cred_str . $nvp_str;
        $response = Paypal::httpPost($ENDPOINT, $req_str);
        //check Response
        if ($response['ACK'] == "Success" || $response['ACK'] == "SuccessWithWarning") {
            //setup redirect URL
            $redirect_url = $REDIRECTURL . urldecode($response['TOKEN']);
            ?>
                <a href="<?php 
            echo $redirect_url;
            ?>
" id='paypalBtn_<?php 
            echo $r;
            ?>
'>
                    <img src='<?php 
            echo payment_url();
            ?>
payments/paypal/paypal.gif' border='0' />
                </a>
                <script>
                    var dg_<?php 
            echo $r;
            ?>
 = new PAYPAL.apps.DGFlow({
                        trigger: "paypalBtn_<?php 
            echo $r;
            ?>
"
                    });
                </script><?php 
        } else {
            if ($response['ACK'] == 'Failure' || $response['ACK'] == 'FailureWithWarning') {
                $redirect_url = '';
                //SOMETHING FAILED
            }
        }
    }
Exemplo n.º 2
0
 if (osc_get_preference('paypal_sandbox', 'payment') == 1) {
     $ENDPOINT = 'https://api-3t.sandbox.paypal.com/nvp';
 }
 $VERSION = '65.1';
 //must be >= 65.1
 //Build the Credential String:
 $cred_str = 'USER='******'&PWD=' . $APIPASSWORD . '&SIGNATURE=' . $APISIGNATURE . '&VERSION=' . $VERSION;
 //Build NVP String for GetExpressCheckoutDetails
 $nvp_str = '&METHOD=GetExpressCheckoutDetails&TOKEN=' . urldecode($token);
 //combine the two strings and make the API Call
 $req_str = $cred_str . $nvp_str;
 $response = Paypal::httpPost($ENDPOINT, $req_str);
 //based on the API Response from GetExpressCheckoutDetails
 $doec_str = $cred_str . '&METHOD=DoExpressCheckoutPayment' . '&TOKEN=' . $token . '&PAYERID=' . $payerid . '&PAYMENTREQUEST_0_CURRENCYCODE=' . urldecode($response['PAYMENTREQUEST_0_CURRENCYCODE']) . '&PAYMENTREQUEST_0_AMT=' . urldecode($response['PAYMENTREQUEST_0_AMT']) . '&PAYMENTREQUEST_0_ITEMAMT=' . urldecode($response['PAYMENTREQUEST_0_ITEMAMT']) . '&PAYMENTREQUEST_0_TAXAMT=' . urldecode($response['PAYMENTREQUEST_0_TAXAMT']) . '&PAYMENTREQUEST_0_DESC=' . urldecode($response['PAYMENTREQUEST_0_DESC']) . '&PAYMENTREQUEST_0_PAYMENTACTION=Sale' . '&L_PAYMENTREQUEST_0_ITEMCATEGORY0=' . urldecode($response['L_PAYMENTREQUEST_0_ITEMCATEGORY0']) . '&L_PAYMENTREQUEST_0_NAME0=' . urldecode($response['L_PAYMENTREQUEST_0_NAME0']) . '&L_PAYMENTREQUEST_0_NUMBER0=' . urldecode($response['L_PAYMENTREQUEST_0_NUMBER0']) . '&L_PAYMENTREQUEST_0_QTY0=' . urldecode($response['L_PAYMENTREQUEST_0_QTY0']) . '&L_PAYMENTREQUEST_0_TAXAMT0=' . urldecode($response['L_PAYMENTREQUEST_0_TAXAMT0']) . '&L_PAYMENTREQUEST_0_AMT0=' . urldecode($response['L_PAYMENTREQUEST_0_AMT0']) . '&L_PAYMENTREQUEST_0_DESC0=' . urldecode($response['L_PAYMENTREQUEST_0_DESC0']) . '&NOTIFYURL=';
 //make the DoEC Call:
 $doresponse = Paypal::httpPost($ENDPOINT, $doec_str);
 $status = Paypal::processDGPayment($doresponse, $response);
 $product_type = explode('x', urldecode($response['L_PAYMENTREQUEST_0_NUMBER0']));
 if ($status == PAYMENT_COMPLETED || $status == PAYMENT_ALREADY_PAID) {
     osc_add_flash_ok_message(__('Payment processed correctly', 'payment'));
     if ($product_type[0] == '101') {
         $item = Item::newInstance()->findByPrimaryKey($product_type[2]);
         $category = Category::newInstance()->findByPrimaryKey($item['fk_i_category_id']);
         View::newInstance()->_exportVariableToView('category', $category);
         $html = '<p>' . __('Payment processed correctly', 'payment') . ' <a href=\\"' . osc_search_category_url() . '\\">' . __('Click here to continue', 'payment') . '</a></p>';
         $url = osc_search_category_url();
     } else {
         if ($product_type[0] == '201') {
             $html = '<p>' . __('Payment processed correctly', 'payment') . ' <a href=\\"' . payment_js_redirect_to(osc_route_url('payment-user-menu')) . '\\">' . __("Click here to continue", 'payment') . '</a></p>';
             $url = payment_js_redirect_to(osc_route_url('payment-user-menu'));
         } else {