Пример #1
0
 function process()
 {
     try {
         //set creentials
         $this->set_credentials();
         if (is_null($this->business) || is_null($this->paypal_url) || is_null($this->api_username) || is_null($this->api_password) || is_null($this->api_signature)) {
             throw new Exception('Unable to process your order.');
         }
         if (!is_array($this->_cart) || !count($this->_cart)) {
             throw new Exception("Please specify cart info.");
         }
         if (!is_array($this->_billing_info) || !count($this->_billing_info)) {
             throw new Exception("Please specify billing info.");
         }
         if (!is_array($this->_shipping_info) || !count($this->_shipping_info)) {
             throw new Exception("Please specify shipping info.");
         }
         if (strcmp($this->_return_url, '') === 0) {
             throw new Exception("Please specify return url.");
         }
         if (strcmp($this->_cancel_url, '') === 0) {
             throw new Exception("Please specify cancel url.");
         }
         if (strcmp($this->_notify_url, '') === 0) {
             throw new Exception("Please specify notify url.");
         }
         //Add cart data
         $i = 1;
         foreach ($this->_cart as $val) {
             $this->add_field('item_name_' . $i, $val['name']);
             $this->add_field('item_number_' . $i, $val['id']);
             $this->add_field('quantity_' . $i, $val['qty']);
             $this->add_field('amount_' . $i, price_format($val['sell_price']));
             $i++;
         }
         //add basic required fields
         $this->add_field('cmd', '_cart');
         $this->add_field('upload', '1');
         $this->add_field('business', $this->business);
         $this->add_field('rm', '2');
         // Return method = POST
         //add discount
         $this->add_field('discount_amount_cart', round_amount($this->_discount));
         //add shipping and handling
         $this->add_field('handling_cart', round_amount($this->_shipping_charge));
         //add tax
         $this->add_field('tax_cart', round_amount($this->_tax));
         //prepare query string of custom data
         $this->add_field('custom', http_build_query($this->_custom));
         //add return url
         $this->add_field('return', $this->_return_url);
         //add cancel url
         $this->add_field('cancel_return', $this->_cancel_url);
         //add notify url
         $this->add_field('notify_url', $this->_notify_url);
         return $this->get_form();
     } catch (Exception $e) {
         $this->error_message = $e->getMessage();
         return FALSE;
     }
 }
 public function doEC()
 {
     $this->set_credentials();
     $PayPalConfig = array('Sandbox' => $this->payment_mode, 'APIUsername' => trim($this->api_username), 'APIPassword' => trim($this->api_password), 'APISignature' => trim($this->api_signature), 'APIVersion' => '97.0', 'APISubject' => '', 'PrintHeaders' => false, 'LogResults' => false, 'LogPath' => '');
     $PayPal = new angelleye\PayPal\PayPal($PayPalConfig);
     $DECPFields = array('token' => $this->_token, 'payerid' => $this->_payer_id, 'returnfmfdetails' => '', 'giftmessage' => '', 'giftreceiptenable' => '', 'giftwrapname' => '', 'giftwrapamount' => '', 'buyermarketingemail' => '', 'surveyquestion' => '', 'surveychoiceselected' => '', 'allowedpaymentmethod' => 'InstantPaymentOnly', 'buttonsource' => '');
     $PaymentOrderItems = array();
     $itemTotalValue = 0;
     $taxTotalValue = 0;
     foreach ($this->_cart as $val) {
         $itemTotalValue += $val['price'] * $val['qty'];
         $Item = array('name' => $val['name'], 'desc' => strip_tags($val['desc']), 'amt' => $val['price'], 'number' => $val['options']['product_id'], 'qty' => $val['qty'], 'taxamt' => 0, 'itemurl' => '', 'itemcategory' => '', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => '');
         array_push($PaymentOrderItems, $Item);
     }
     if (!empty($this->_discount) && $this->_discount != 0) {
         $itemTotalValue += -round_amount($this->_discount);
         $discount_apply = array('name' => 'Discount', 'amt' => -round_amount($this->_discount), 'number' => '', 'qty' => 1, 'taxamt' => 0);
         array_push($PaymentOrderItems, $discount_apply);
     }
     if (!empty($this->_coupon) && $this->_coupon != 0) {
         $itemTotalValue += -round_amount($this->_coupon);
         $coupon_apply = array('name' => 'Coupon', 'amt' => -round_amount($this->_coupon), 'number' => '', 'qty' => 1, 'taxamt' => 0, 'desc' => $_SESSION['coupon_details']['code']);
         array_push($PaymentOrderItems, $coupon_apply);
     }
     $shippingTotal = round_amount($this->_shipping_charge);
     $taxTotalValue = round_amount($this->_tax);
     $discountTotal = round_amount($this->_discount);
     $orderTotal = $itemTotalValue + $taxTotalValue + $shippingTotal;
     $orderTotal = $orderTotal - $this->_shipping_discount;
     $Payments = array();
     $Payment = array('amt' => round_amount($orderTotal), 'currencycode' => 'USD', 'itemamt' => $itemTotalValue, 'shippingamt' => $shippingTotal, 'shipdiscamt' => -$this->_shipping_discount, 'insuranceoptionoffered' => '', 'handlingamt' => '', 'redeemedofferamount' => '', 'taxamt' => $taxTotalValue, 'desc' => 'This is a test order.', 'custom' => http_build_query($this->_custom), 'invnum' => '', 'notifyurl' => $this->_notify_url, 'shiptoname' => $this->address_fill('S', 'name'), 'shiptostreet' => $this->address_fill('S', 'address'), 'shiptocity' => $this->address_fill('S', 'city'), 'shiptostate' => $this->address_fill('S', 'state'), 'shiptozip' => $this->address_fill('S', 'zip_code'), 'shiptocountry' => $this->address_fill('S', 'country'), 'shiptophonenum' => $this->address_fill('S', 'phone'), 'notetext' => 'This is a test note before ever having left the web site.', 'allowedpaymentmethod' => 'InstantPaymentOnly', 'paymentaction' => 'Sale', 'paymentrequestid' => '', 'sellerpaypalaccountid' => '');
     $Payment['order_items'] = $PaymentOrderItems;
     array_push($Payments, $Payment);
     $UserSelectedOptions = array('shippingcalculationmode' => '', 'insuranceoptionselected' => '', 'shippingoptionisdefault' => '', 'shippingoptionamount' => '', 'shippingoptionname' => '');
     $PayPalRequest = array('DECPFields' => $DECPFields, 'Payments' => $Payments);
     $PayPalResult = $PayPal->DoExpressCheckoutPayment($PayPalRequest);
     return $PayPalResult;
 }
Пример #3
0
 public function setEC()
 {
     //set creentials
     $this->set_credentials();
     $PayPalConfig = array('Sandbox' => $this->payment_mode, 'APIUsername' => trim($this->api_username), 'APIPassword' => trim($this->api_password), 'APISignature' => trim($this->api_signature), 'APIVersion' => '97.0', 'APISubject' => '', 'PrintHeaders' => false, 'LogResults' => false, 'LogPath' => '');
     $PayPal = new angelleye\PayPal\PayPal($PayPalConfig);
     $SECFields = array('token' => '', 'maxamt' => '', 'returnurl' => $this->_return_url, 'cancelurl' => $this->_cancel_url, 'callback' => '', 'callbacktimeout' => '', 'callbackversion' => '', 'reqconfirmshipping' => '0', 'noshipping' => '', 'allownote' => '1', 'addroverride' => '1', 'localecode' => '', 'pagestyle' => isset($this->_page_design['pagestyle']) ? $this->_page_design['pagestyle'] : '', 'hdrimg' => isset($this->_page_design['hdrimg']) ? $this->_page_design['hdrimg'] : '', 'logoimg' => isset($this->_page_design['logoimg']) ? $this->_page_design['logoimg'] : '', 'cartbordercolor' => isset($this->_page_design['cartbordercolor']) ? $this->_page_design['cartbordercolor'] : '', 'hdrbordercolor' => isset($this->_page_design['hdrbordercolor']) ? $this->_page_design['hdrbordercolor'] : '', 'hdrbackcolor' => isset($this->_page_design['hdrbackcolor']) ? $this->_page_design['hdrbackcolor'] : '', 'payflowcolor' => isset($this->_page_design['payflowcolor']) ? $this->_page_design['payflowcolor'] : '', 'skipdetails' => '', 'email' => '', 'solutiontype' => 'Sole', 'landingpage' => 'Login', 'channeltype' => 'Merchant', 'giropaysuccessurl' => '', 'giropaycancelurl' => '', 'banktxnpendingurl' => '', 'brandname' => isset($this->_page_design['channel_name']) ? $this->_page_design['channel_name'] : '', 'customerservicenumber' => '', 'giftmessageenable' => '', 'giftreceiptenable' => '', 'giftwrapenable' => '', 'giftwrapname' => 'Box with Ribbon', 'giftwrapamount' => '', 'buyeremailoptionenable' => '1', 'surveyquestion' => '', 'surveyenable' => '1', 'buyerid' => '', 'buyerusername' => '', 'buyerregistrationdate' => '', 'allowpushfunding' => '');
     // Basic array of survey choices.  Nothing but the values should go in here.
     $SurveyChoices = array('Yes', 'No');
     $PaymentOrderItems = array();
     $itemTotalValue = 0;
     $taxTotalValue = 0;
     foreach ($this->_cart as $val) {
         $itemTotalValue += $val['price'] * $val['qty'];
         $Item = array('name' => $val['name'], 'desc' => strip_tags($val['desc']), 'amt' => $val['price'], 'number' => $val['options']['product_id'], 'qty' => $val['qty'], 'taxamt' => 0, 'itemurl' => '', 'itemcategory' => '', 'itemweightvalue' => '', 'itemweightunit' => '', 'itemheightvalue' => '', 'itemheightunit' => '', 'itemwidthvalue' => '', 'itemwidthunit' => '', 'itemlengthvalue' => '', 'itemlengthunit' => '', 'ebayitemnumber' => '', 'ebayitemauctiontxnid' => '', 'ebayitemorderid' => '', 'ebayitemcartid' => '');
         array_push($PaymentOrderItems, $Item);
     }
     if (!empty($this->_discount) && $this->_discount != 0) {
         $itemTotalValue += -round_amount($this->_discount);
         $discount_apply = array('name' => 'Discount', 'amt' => -round_amount($this->_discount), 'number' => '', 'qty' => 1, 'taxamt' => 0);
         array_push($PaymentOrderItems, $discount_apply);
     }
     if (!empty($this->_coupon) && $this->_coupon != 0) {
         $itemTotalValue += -round_amount($this->_coupon);
         $coupon_apply = array('name' => 'Coupon', 'amt' => -round_amount($this->_coupon), 'number' => '', 'qty' => 1, 'desc' => $_SESSION['coupon_details']['code'], 'taxamt' => 0);
         array_push($PaymentOrderItems, $coupon_apply);
     }
     $shippingTotal = round_amount($this->_shipping_charge);
     $taxTotalValue = round_amount($this->_tax);
     $discountTotal = round_amount($this->_discount);
     $orderTotal = $itemTotalValue + $taxTotalValue + $shippingTotal;
     $orderTotal = $orderTotal - $this->_shipping_discount;
     $Payments = array();
     $Payment = array('amt' => round_amount($orderTotal), 'currencycode' => 'USD', 'itemamt' => $itemTotalValue, 'shippingamt' => $shippingTotal, 'shipdiscamt' => -$this->_shipping_discount, 'insuranceoptionoffered' => '', 'handlingamt' => '', 'redeemedofferamount' => '', 'taxamt' => $taxTotalValue, 'desc' => '', 'custom' => '', 'invnum' => '', 'notifyurl' => $this->_notify_url, 'shiptoname' => $this->address_fill('S', 'name'), 'shiptostreet' => $this->address_fill('S', 'address'), 'shiptocity' => $this->address_fill('S', 'city'), 'shiptostate' => $this->address_fill('S', 'state'), 'shiptozip' => $this->address_fill('S', 'zip_code'), 'shiptocountry' => $this->address_fill('S', 'country'), 'shiptophonenum' => $this->address_fill('S', 'phone'), 'notetext' => '', 'allowedpaymentmethod' => 'InstantPaymentOnly', 'paymentaction' => 'Sale', 'paymentrequestid' => '', 'sellerpaypalaccountid' => '');
     $Payment['order_items'] = $PaymentOrderItems;
     array_push($Payments, $Payment);
     $BuyerDetails = array('buyerid' => '', 'buyerusername' => '', 'buyerregistrationdate' => '');
     // For shipping options we create an array of all shipping choices similar to how order items works.
     $ShippingOptions = array();
     $Option = array('l_shippingoptionisdefault' => '', 'l_shippingoptionname' => '', 'l_shippingoptionlabel' => '', 'l_shippingoptionamount' => '');
     array_push($ShippingOptions, $Option);
     $BillingAgreements = array();
     $Item = array('l_billingtype' => 'MerchantInitiatedBilling', 'l_billingagreementdescription' => 'Billing Agreement', 'l_paymenttype' => 'Any', 'l_billingagreementcustom' => '');
     array_push($BillingAgreements, $Item);
     $PayPalRequest = array('SECFields' => $SECFields, 'SurveyChoices' => $SurveyChoices, 'BillingAgreements' => $BillingAgreements, 'Payments' => $Payments);
     $SetExpressCheckoutResult = $PayPal->SetExpressCheckout($PayPalRequest);
     //echo '<a href="' . $SetExpressCheckoutResult['REDIRECTURL'] . '">Click here to continue.</a><br /><br />';
     //echo '<pre />';
     return $SetExpressCheckoutResult;
 }
Пример #4
0
 function submit_order()
 {
     $form = $this->input->post();
     $shipment = array();
     $payment = array();
     if ($this->session->userdata('shipping_info')) {
         $shipment = $this->session->userdata('shipping_info');
     }
     if ($this->session->userdata('billing_info')) {
         $payment = $this->session->userdata('billing_info');
     }
     $user_id = $this->check_existing_user();
     $process_type = 'authorize';
     if (strcmp($form['pay_type'], 'paypal') === 0) {
         $process_type = 'paypal';
     }
     switch ($process_type) {
         case 'authorize':
             $cards = array('payment_type' => $form['pay_type'], 'cc_name' => $form['cc_name'], 'cc_number' => $form['cc_number'], 'cc_month' => $form['exp_month'], 'cc_year' => $form['exp_year'], 'cc_ccd' => $form['cc_ccd']);
             $this->session->set_userdata('payment_card_details', $cards);
             $this->create_orders('authorize', $user_id);
             $so_id = $this->session->userdata('so_id');
             //if(!$so_id)
             //echo json_encode(array("status"=>"Order Creation Failed."));exit;
             $this->load->library('authorize');
             $shipment_info = $this->session->userdata('shipping_info');
             $payment = $this->session->userdata('billing_info');
             $card_details = $this->session->userdata('payment_card_details');
             $tax = $this->session->userdata['tax_amt'];
             $shipping_cost = $this->session->userdata['ship_amt'];
             $amount = round_amount($this->cart->total()) + round_amount($shipping_cost['shipping_amt']) + round_amount($tax['tax_amt']);
             $params = array();
             $params['shipping_info'] = $shipment_info;
             $params['billing_info'] = $payment;
             $params['card_details'] = $card_details;
             $params['payable_amount'] = $amount;
             $params['invoice_num'] = $so_id;
             //format a description to attach with order details which will be usefull to identify the order
             $description = '';
             foreach ($this->cart->contents() as $row) {
                 $temp = isset($row['sku']) ? "{$row['sku']}-{$row['qty']}" : "{$row['id']}-{$row['qty']}-";
                 $description .= strcmp($description, '') === 0 ? $temp : ",{$temp}";
             }
             $description = "Item(s):{$description}.";
             /*
              *check if the length of description is greater than 250.
              *Because authorize.net wont allow more than 255 characters
              */
             if (strlen($description) > 250) {
                 $description = substr($description, 0, 250);
             }
             $params['description'] = $description;
             //initialize params
             $this->authorize->initialize($params);
             $auth_status = $this->authorize->process_order();
             $response = $this->authorize->get_response();
             if ($auth_status === FALSE) {
                 $update_data = array('order_status' => 'FAILED', 'paid_status' => 'N');
                 $this->db->where('id', $so_id);
                 $this->db->update('sales_order', $update_data);
                 $error_message = isset($response[3]) ? $response[3] : 'Payment could not be processed.';
                 $this->checkout_model->addaction_loginfo('sales_order', 'Payment Declined:' . $error_message, $so_id);
             } else {
                 $update_data = array();
                 $update_data['txn_id'] = $response[6];
                 $update_data['cc_last_digits'] = $response[50];
                 $this->db->where('id', $so_id);
                 $this->db->update('sales_order', $update_data);
                 $this->is_paid = TRUE;
                 $this->paid_amount = $amount;
                 $this->after_payment($so_id);
             }
             break;
     }
     $message = 'success';
     $status = 'success';
     $this->session->set_flashdata('message', 'Your Order has been processed successfully. Thank You.');
     echo json_encode(array('status' => $status, 'message' => $message));
 }