I am using the Bitmex class from:
https://github.com/y0un1verse/bitmex-api-php/blob/master/BitMex.php
I dont have any issues using the functions already there. But when I tried adding my own function, it's not working properly.
the original code for CANCELLING ALL ORDERS is:
public function cancelAllOpenOrders($text = "") {
$symbol = self::SYMBOL;
$data['method'] = "DELETE";
$data['function'] = "order/all";
$data['params'] = array(
"symbol" => $symbol,
"text" => $text
);
return $this ->authQuery($data);
}
the code above works just fine, cancelling all the orders.. however I want to cancel only one order using order ID, so I made this function:
public function cancelOpenOrder($orderID) {
$symbol = self::SYMBOL;
$data['method'] = "DELETE";
$data['function'] = "order";
$data['params'] = array(
"orderID" => $orderID
);
return $this ->authQuery($data);
}
However this one returns an error:
BitMex error (ValidationError) : orderIDs or clOrdIDs must be sent. false
Even if I added the orderID or clOrdID, it is not sent properly.
Anyone could point me to the right direction? Thanks in advance!
Related
I want to update a product in laravel, but it does not work properly,
my Controller's update method looks like this:
public function updateProduct(Request $request)
{
# Get input values
$data = $request->all();
$productID = $data['id'];
$product = Product::find($productID);
$product->fill($data);
# Validate input
$validator = Validator::make($request->all(), Product::$rules);
if ($product->save())
{
# save language selection
$lsCounter = 0;
$langSelecName = $request->input('language');
$langSelecFile = $request->file('language');
if ($langSelecName)
{
$projectPath = $dProjectPath . "languages";
foreach ($langSelecName as $langSelecNameKey => $langSelecNameValue)
{
if ($langSelecFile[$lsCounter]['input_vid_lang'] != null)
{
$langVidFileName = $langSelecFile[$lsCounter]['input_vid_lang']->getClientOriginalName();
$languages = new Language();
$languages['short_name'] = $langSelecNameValue;
$languages['input_video'] = $projectLangPath . '\\' . $langVidFileName;
$languages->product()->associate($product);
$langData = [
'languagesShortName' => $languages['short_name'],
'languagesInputVideo' => $languages['input_video']
];
$intProductID = intval($productID);
$findLangId = $languages->find($intProductID);
$findLangId->fill($langData);
if ($languages->save())
{
$langSelecFile[$lsCounter]['input_vid_lang']->move($projectLangPath, $langVidFileName);
}
}
$lsCounter++;
}
}
} else {
return redirect()->route('editProduct', $productID)->with('message', 'Error')->withInput();
}
I get the following error after I try to update it, the error looks like this:
Call to a member function fill() on null
And it points to this line:
$findLangId->fill($langData);
I appreciate some help, thank you.
Edit
Ok people said that $intProductRomID is null, but I get the correct product id if I dd($intProductRomID).
As per the comments, the following line is return null:
$findLangId = $languages->find($intProductRomID);
Meaning this won't be valid:
$findLangId->fill($langData);
In other words, if you were to var_dump out $languages->all(), you will not find $intProductRomID in there. If you are unsure, swap out ->find with ->findOrFail() (which, considering you aren't doing any error catching or checking, you probably should be using it instead).
Edit
After some conversation in the comments, it has been established that the wrong field was being used for reference. Use a where instead:
$languages->where('product_rom_id', $intProductRomID);
I am building a system where i need to update the value in the database field but before doing that i need to take the current value in the database then adding it to the current value the following is a code from the controller.
public function transfer_amount(){
$email = $this->input->post('view');
$this->load->model('user_model');
$data['user_balance'] = $this->user_model->fetch_balance($email);
$data['balance'] = $this->input->post('amount');
$data['total'] = $this->math->add($data['balance'],$data['user_balance']);
$data = array(
'balance' => $data['total'],
);
if($this->user_model->transfer_amount($data,$email)== true){
$this->load->view('layer_service/success',$data);
}
else
{
$this->load->view('layer_service/unsuccessfull',$data);
}
}
}
then the code in the module that fetch the current balance from the database is as following.
function fetch_balance($email){
$this->db->select('balance');
$this->db->from('tbl_users');
$this->db->where('email', $email);
$query = $this->db->get();
$result = $query->result();
return $result;
}
not sure but look at this part - don't call it $data because i think thats messing you up later
for example call it $balance
$balance = array(
'balance' => $data['total'],
);
// pass the $balance to your model method
if($this->user_model->transfer_amount($balance,$email) == true){
// keeping $data here to pass to the view
$this->load->view('layer_service/success',$data);
}
getting the balance should be wrapped in an if in case it fails
if( ! $data['user_balance'] = $this->user_model->fetch_balance($email) )
{
$this->_showNoUserFor($email) ;
}
another suggestion:
$email = $this->input->post('view');
validate the email first before sending it to your database table. codeigniter form validation library works really well.
======
EDIT ok this part
$data['total'] = $this->math->add($data['balance'],$data['user_balance']);
means that you have a model called math with a method called add()
so if you don't have that you would just use php math which is very simple
$data['total'] = $data['balance'] + $data['user_balance'] ;
of course this assumes everything has been validated first so you are actually adding together two numbers.
i am writing a program using mvc , and because the program i am writing is for admitting bank transactions, the resaults this program gives me is very important to me. and i need this to work without any logical errors and everything should workout with needed focus and giving me the exact thing i expect it to give. the thing that i want it to do for me is that some information will be sent out to the program with web service (like price, info, etc...) and then using a controller it checks the information and calls for the module, and sends the information to it. the it puts the module information to a stdclass and then using the PDO module it creates a transaction. and while the transaction is at work an insert command is sent for the database, and then we have a SELECT command and the program works well even after the insert command but while SELECT is at work , we have repetitive IDs which is the problem here:
my code:
//WSDL Creattor And Class
<?php
ini_set("soap.wsdl_cache_enabled", 1);
set_time_limit(300);
class wsdl extends Controller
{
public function index()
{
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
$servidorSoap = new SoapServer('http://' . $_SERVER['SERVER_NAME'] . '/wsdl');
$servidorSoap->setClass('wsdl');
$servidorSoap->handle();
}
}
public function request($pin = null, $amount = 1, $callback = null, $orderid = null, $desc = null)
{
if(empty($callback))
return -10; // call back is empty.
if (empty($pin) && $result->pin != $pin)
return -1; // pin invalid
$this->Model("payment");
$au = $this->mod->Request($result, $amount, $callback, $orderid, $desc);
return $au;
}
}
payment model:
<?php
class Payment_mod extends Model
{
public function Request($gateway, $amount, $callback, $orderid, $description)
{
// using pdo module
$this->DB->CONNECT->beginTransaction();
try {
$trans = new stdClass;
$trans->gateway_id = $gateway->id;
$trans->au = str_replace('.', '_temp_', microtime(true));
$trans->price = $amount;
$trans->order_id = $orderid;
$trans->ip = $_SERVER['REMOTE_ADDR'];
$trans->time = time();
$trans->call_back = $callback;
$trans->description = $description;
$this->DB->Insert("trans", $trans); // insert into table trans …
$id = $this->DB->Fetch("trans", "`gateway_id` =" . $trans->gateway_id . " AND `price`=".$trans->price." AND time = " . $trans->time)->id; // select id from trans where …
$u = new stdClass;
$u->t_id = $id;
$this->DB->Insert("test",$u); // insert into test . it for test table for check result
$this->DB->CONNECT->commit();
} catch (Exception $e) {
$this->DB->CONNECT->rollBack();
return -9; // return unknow error.
}
return $id;
}
}
for understanding where the problem exactly is and how many times each ID repeats itself, i added a table and i got the amount of return data of SELECT and put it into the database. and when i hold the f5 key for some seconds it shows that each ID repeats nearly 9 times.
screenshot:
http://uploads.im/biWEn.jpg
note: this picture shows the amount of repeat of IDs.
where is the problem? i need this to repeat a specific ID for each call.
i did the exact thing in YII framework and i had no problem there and the progam worked exactly as i needed it to. i'd be glad if you help me.
I'm working on a php project but I have a problem with the database , I use this code to get data from the database :
public function getSeenAction(Request $request , $notificationId)
{
$sessionId = $request->headers->get('SessionID');
if( $sessionId == null )
{
//return new Response("Unauthorized",401);
}
$notificationRepo = $this->getDoctrine()->getRepository('MegasoftEntangleBundle:Notification');
$notification = $notificationRepo->findOneById($notificationId);
if($notification == null)
{
return new Response("Notification not found" ,404);
}
$seen = $notification->getSeen();
$response = new JsonResponse();
$response->setdata(array('seen'=>$seen));
$response->setStatusCode(200);
return $response;
}
I tried the same code with other tables and it worked , but whenever I retrive data from the Notification table it always give null , although the table contains the data.
$notificationRepo = $this->getDoctrine()->getRepository('MegasoftEntangleBundle:Notification');
$notification = $notificationRepo->findAll();
var_dump(notification);
Is this code returns you something ? Probably the code of your NotificationRepository.php is not good, can you put it on ?
Try using find instead of findOneById if you just want to find record by Id.
On the other hand if you want to use findOneBy the passed argument for criteria should be an array.
$result = $notificationRepo->find($notificationId);
Or
$result = $notificationRepo->findOneBy(array('id' => $notificationId));
Or
make sure you have a proper code for findOneById in your NotificationRepository.php file
Then you can check
if (!empty($result)) { ... }
My question is quite simple. I need to change the shipping rate cost in one page checkout to "0" once the user select COD as payment method in one page checkout. I think I can do this easely with an observer. Could you please helpme to know what event should I observe?.
Can I use checkout_controller_onepage_save_shipping_method ?. Any kind of help will be highly appreciated!!
Details Posted By OP as answer
I override the Mage_Checkout_Model_Type_Onepage class and modify the savePayment method. Then I did this:
1.- A first try:
public function savePayment($data)
{
.....
....
$payment = $quote->getPayment();
$payment->importData($data);
$quote->save();
//My custom code
if($data['method']=='cashondelivery'){
$shipping = $quote->getShippingAddress();
$address = $quote->getBillingAddress();
$shipping->addData($address)->setShippingMethod('flatrate_flatrate');
}
Where my flatrate_flatrate is 0. Unfortunately it doesn't work well. This snippet set to 0 my Grant Total.
My second try was:
public function savePayment($data)
{
.....
....
$payment = $quote->getPayment();
$payment->importData($data);
$quote->save();
//My custom code
if($data['method']=='cashondelivery'){
$this->getQuote()->getShippingAddress()->setShippingAmount(0);
$this->getQuote()->getShippingAddress()->setBaseShippingAmount(0);
}
This code works but only a few times, I don't understand why ??.. Could somebody helpme to fix this please?. Any kind of help will be highly appreciated.
Kind regards!
Ok. Now I have this and it works but it doesn't update the grand total amount. Even the order is processed with the normal shipping cost. I mean, finally it doesn't update anything. Could somebody in someway give me a hand on this please?.
if($data['method']=='cashondelivery'){
$quote->getShippingAddress()->setShippingMethod('flatrate_flatrate');
$quote->getShippingAddress()->setShippingAmount(0);
$quote->getShippingAddress()->setBaseShippingAmount(0);
$quote->getShippingAddress()->setShippingInclTax(0);
$quote->getShippingAddress()->setBaseShippingInclTax(0);
$quote->collectTotals();
$quote->save();
}
Warming regards!
Ok, I did something crazy but it seems it works (at least partially). I override Mage_Checkout_OnepageController too and add it a new method call actualizaShippingMethodAction.
It looks like this:
public function actualizaShippingMethodAction()
{
if ($this->_expireAjax()) {
return;
}
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost('shipping_method', '');
$result = $this->getOnepage()->saveShippingMethod($data);
// $result will contain error data if shipping method is empty
if (!$result) {
$this->getOnepage()->getQuote()->collectTotals();
}
$this->getOnepage()->getQuote()->collectTotals()->save();
}
}
Now in my original class that is overriding (Mage_Checkout_Model_Type_Onepage) I did this.
if($data['method']=='cashondelivery'){
$cliente = new Varien_Http_Client();
$_configuracion = array('maxredirects'=>5, 'timeout'=>30);
$llamada = Mage::getBaseUrl()."checkout/onepage/actualizaShippingMethod/";
$cliente->setUri($llamada)
->setConfig($_configuracion)
->setMethod(Zend_Http_Client::POST)
->setParameterPost('shipping_method','flatrate_flatrate');
$respuesta = $cliente->request();
$quote->getShippingAddress()->setShippingAmount(0);
$quote->getShippingAddress()->setBaseShippingAmount(0);
$quote->getShippingAddress()->setShippingInclTax(0);
$quote->getShippingAddress()->setBaseShippingInclTax(0);
$quote->collectTotals()->save();
}
$this->getCheckout()
->setStepData('payment', 'complete', true)
->setStepData('review', 'allow', true);
return array();
Now the order is passing without shipping cost as spected but the order review (summary) is not updating the final costs. And I thinks this solution has a bug because if the user returns and select another payment method the shipping cost is 0 again.
Any kind of help, whatever, will be highly, highly appreciated
THANKS
Finally I have a solution and I think is an answer to the original question. If not please pardon me.
Forget to override savePayment($data) on Mage_Checkout_Model_Type_Onepage. Just focus on overriding Mage_Checkout_OnepageController, and add to the savePaymentAction() method the following code.
$data = $this->getRequest()->getPost('payment', array());
/*Custom code*/
if($data['method']=='cashondelivery'){//Only if payment method is cashondelivery
$result = $this->getOnepage()->savePayment($data);
// get section and redirect data
$redirectUrl = $this->getOnepage()->getQuote()->getPayment()->getCheckoutRedirectUrl();
if (empty($result['error']) && !$redirectUrl) {
$this->loadLayout('checkout_onepage_review');
$result['goto_section'] = 'review';
$result['update_section'] = array(
'name' => 'review',
'html' => $this->_getReviewHtml()
);
}
if ($redirectUrl) {
$result['redirect'] = $redirectUrl;
}
//Update totals for Shipping Methods
$resultado = $this->getOnepage()->saveShippingMethod('flatrate_flatrate');
$this->getOnepage()->getQuote()->collectTotals()->save();
}else{
$result = $this->getOnepage()->savePayment($data);
// get section and redirect data
$redirectUrl = $this->getOnepage()->getQuote()->getPayment()->getCheckoutRedirectUrl();
if (empty($result['error']) && !$redirectUrl) {
$this->loadLayout('checkout_onepage_review');
$result['goto_section'] = 'review';
$result['update_section'] = array(
'name' => 'review',
'html' => $this->_getReviewHtml()
);
}
if ($redirectUrl) {
$result['redirect'] = $redirectUrl;
}
//Return the original values according with the initial user sellection
//I use a session variable to store the original selection
$shippingMethod = Mage::getSingleton('core/session')->getShippingInicial();
$resultado = $this->getOnepage()->saveShippingMethod($shippingMethod);
$this->getOnepage()->getQuote()->collectTotals()->save();
}
} catch (Mage_Payment_Exception $e) {
if ($e->getFields()) {
...
Then you have to override saveShippingMethodAction() and add the following code.
...
$result = $this->getOnepage()->saveShippingMethod($data);
//We store the Shipping Method initial selection
Mage::getSingleton('core/session')->setShippingInicial($data);
// $result will contain error data if shipping method is empty
if (!$result) { ...
If you test this you will find that it works as expected. But now it takes 2 loading times to correctly show the total costs in the review part. I read this question (IWD one page checkout extension Magento: review refresh) but it doesn't help a lot.
Could somebody point me in the right direction to update the review part twice?.
WARMING REGARDS!
Could somebody have an idea how to achieve this?. Regards!