woocommerce REST API Get customer by email - woocommerce-rest-api

Get customer by email
https://localhost/biobays/wp-json/wc/v2/customers/2 getting customer by id is working. But
https://localhost/biobays/wp-json/wc/v2/customers/email/test#t.com or https://localhost/biobays/wp-json/wc/v2/customers?email=test#t.com are not working
I expect the user info do be retrieved.
I'm having an empty response.
PS: this work great on old v3 https://localhost/biobays/wc-api/v3/customers/email/test#t.com

Joe,
I make a little test and this is the call you need to do to the API:
$params = array("email" => "test#t.com");
$getContact = $wcApi->get('customers',$params);
echo "<pre>";
print("<pre>".print_r($getContact , true)."</pre>");
echo"</pre>";
If you will test the url make the call like this:
https://localhost/biobays/wp-json/wc/v2/customers?email=test%40t.com&consumer_key=YOUR_CONSUMER_KEY&consumer_secret=YOUR_CONSUMER_SECRET
If no e-mail exists one empty array is returned.

For new version api tested on 5.8.x , this seems to working fine
https://yourdomain.com/wp-json/wc/v3/customers?email=xxxxxxx#gmail.com

Related

What is wrong with my paypal process to receive webhook notifications?

So this is what i did so far and it doesn't work, i will appreciate any help on the matter:
my goal is to post back any webhook event that occur in my paypal sandbox account.
So i have 2 accounts,
one that belongs to the receiver of the money, call it "facilitator",
one that belong to the "buyer",
Now in my account,there is a Sandbox webhooks configuration, so i entered the following:
https://csdieuqkzo.localtunnel.me
goes without saying that this comes from localtunnel.me.
So in my project, i do a simple sale using the api... this is the full create sale process:
$payer = new Payer();
$payer->setPayment_method('paypal');
//dd($payer);
$item = new Item();
$item->setQuantity('1');
$item->setName('benny');
$item->setPrice('7.41');
$item->setCurrency('USD');
$item->setSku('blah');
// //var_dump($item);
$items = new ItemList();
$items->addItem($item);
//var_dump($items);
$amountDetails = new Details();
$amountDetails->setSubtotal('7.41');
$amountDetails->setTax('0.03');
$amountDetails->setShipping('0.03');
$amount = new Amount();
$amount->setCurrency('USD');
$amount->setTotal('7.47');
$amount->setDetails($amountDetails);
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('This is the payment transaction description.');
$transaction->setItemList($items);
// echo '<pre>';
// print_r($transaction);
$RedirectUrls = new RedirectUrls();
$RedirectUrls ->setReturnUrl('https://csdieuqkzo.localtunnel.me/#/pricing');
$RedirectUrls ->setCancelUrl('https://csdieuqkzo.localtunnel.me/#/');
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$payment->setRedirectUrls($RedirectUrls);
// echo '<pre>';
// print_r($payment);
// dd();
$response = $payment->create($this->apiContext)->toarray();
Session::put('pay_id',$response['id']);
return Response::json($response);
After this there is a redirect to paypal, approval and when it comes back to my site, it excute with the following:
$payerId = Input::get('payerId');
$payment = Payment::get(Session::get('pay_id'), $this->apiContext);
//return $payerId;
$paymentExecution = new PaymentExecution();
$paymentExecution->setPayer_id($payerId);
$approval = $payment->execute($paymentExecution, $this->apiContext)->toarray();
return Response::json($approval);
Then an object is coming in saying the state of this transaction is approved, super, but i don't see any post to the webhook url i defined earlier...Now how did i test it?
I wrote a simple script to the post method of my root (in laravel):
Route::post('/',function(){
$myfile = fopen("bennyfile.txt", "a") or die("Unable to open file!");
$txt = "\nouterequested";
fwrite($myfile, $txt);
fclose($myfile);
});
Means whenever a post request is coming to the following url (in my case, a post to the root of:https://csdieuqkzo.localtunnel.me
I just want to add a line, that's it...but it doesn't update anything!...
for example if i do a post request from postman to the same place, all is good, but when a sale is approved, or any other action, nothing is happening.
Why?
This is a paypal document which helps you understand how webhooks works.
https://developer.paypal.com/docs/integration/direct/rest-webhooks-overview/
webhooks is http call back mechanism, ideally, you will need a valid url as your webhooks endpoint to test the webhooks notification message posted by PayPal. If you did sale using paypal wallet, you should get PayPal's webhooks notification message in JSON format at your endpoint. webhooks doesn't support direct credit card case yet.
If you want to test your listener script on local, you can use postman tool to post the sample message to your local url and test.
Using "localhost" isn't going to work because when PayPal's servers hits that address they're just hitting themselves. You need to setup DNS to point a domain to a virtual server on your local machine instead so that you can use a fully qualified domain name instead of localhost.

Get the first product id in a magento system via soap api (2)?

Question: Is there a way (api call) to get the first product id in a magento install via the soap api.
I'm attempting to download all the products from a magento system and insert them into a different database (I do the conversion myself so that's not a bother) What is hard to understand though is how do I get a list of the product id's without getting all of them, if all I know is that the site is up.
Here's the info I have.
soap end point
soap username
soap apikey (aka password)
Here's what I don't know.
the id of any of the products
the date any of the products were created on or last edited.
For my initial load, I have to do a where product id in, because I expect 20 to 40k product lists won't come back in one soap call.
So I call
where id in (1 -> 100) Nope
where id in (101-> 200) Nope..
Now as you can imagine that code smells something fierce. It works, but I have to think there is a better way..
To expand my question: Is there a better way?
I can post the XML that I'm sending if that helps. The language I'm using to create the soap(xml) is vim, so I don't have code I can paste.
Try This
$client = new SoapClient('http://localhost/magento8/index.php/api/soap/?wsdl');
$session = $client->login('soap username', 'soap apikey');
$filters=array('entity_id'=>array(array('lt'=>'1','gt'=>'100')));//get fist 100 result
$result = $client->call($session, 'catalog_product.list',array($filters));
var_dump($result);
for more attributes check this
http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento

How do I connect to external API from Magento

I am looking for some assistance in creating an API based module to push customer information out of Magento into a Third party loyalty program.
So far I have created a basic module but cannot find any good information on creating API based modules in Magento and could really do with some advice please...
I need to somehow hook into the Checkout success page in Magneto and add a form the will POST the customers information (name, address etc) to a third party loyalty program. I also need to be able to login to complete the billing information etc...
Does anyone know of any handy tutorials or documentation for such an implementation?
So far I have setup an API user with the appropriate roles. I have also created a very basic module for test purpses but browsing to the file I get a 404 error
apitest.php
<?php
$proxy = new SoapClient('http://mysite.com/api/?wsdl'); //edit the address and put the url to your magento here
$sessionId = $proxy->login('######', '#######'); // put in the info for your user here
echo "Login ID : $sessionId";
$result = $proxy->call($sessionId, 'Mymodule.testConnection', array('param1' => ' This string was sent from soap client'));
echo $result;
Objectmodel/api.php
<?php
class MyModule_MyModule_Model_ObjectModel_Api extends Mage_Api_Model_Resource_Abstract
{
public function testConnection($arg)
{
return "Hello World! My argument is : " . $arg;
}
}
I followed the example from here for getting a basic 'Hello world' module up and running if anyone could assist me with getting the correct setup I would be grateful
Instead of connect magento API you can create customer like this.
define('INCLUDE_PATH', '/var/www/QA/mojostage/app/');
define('INCLUDE_FILE', 'Mage.php');
Mage::app();
$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId($wesite_id);
$customer->loadByEmail($customer_email);
/*
* Check if the email exist on the system.
* If YES, it will not create a user account.
*/
if (!$customer->getId()) {
//setting data such as email, firstname, lastname, and password
$customer->setEmail($customer_email);
$customer->setTaxvat($value['cus_vatnumber'])
->setCreatedAt($date1)
->setDob($value['date_of_birth'])
->setGroupId($cus_group_id)
->setConfirmation($is_active)
->setCreatedIn('Admin')
->setStoreId($store_id)
->setWebsiteId($wesite_id)
->setEntityId($value['cus_id']);
$customer->setFirstname($customer_fname);
$customer->setLastname($customer_lname);
$customer->setPassword($value['password']);
$subscriber = Mage::getModel('newsletter/subscriber');
$subscriber->setStoreId($store_id)
->setCustomerId($value['cus_id'])
->setSubscriberEmail($customer_email)
->setSubscriberStatus($value['cus_spam'])
->setSubscriberConfirmCode($subscriber->randomSequence());
}
//the save the data and send the new account email.
$customer->save();
$subscriber->save();

cannot get full shopping cart detail using GetExpressCheckoutDetails

I am currently testing an online store using a custom cart within paypal sandbox.
I am able to go trough all transcation steps properly
setExpressCheckout-> pay -> DoExpressCheckout.
During the DoExpressCheckout step I think it would be the good time to update my database with the order. For that I use the GetExpressCheckoutDetails function to retrieve the content of the transaction.
Sadly this function return everything paypal has to offer but miss the content of my cart. All i can get is the detail of one item. If the transaction involve multiple items i would only get the details of the first one.
Here is my code (mostly taken from paypal samples) :
$token =urlencode( $_REQUEST['token']);
$payerId=urlencode( $_REQUEST['PayerID']);
$getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($token);
$getExpressCheckoutReq = new GetExpressCheckoutDetailsReq();
$getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
$paypalService = new PayPalAPIInterfaceServiceService();
$getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
$details = $getECResponse->GetExpressCheckoutDetailsResponseDetails;
// $details->PaymentDetails->PaymentDetailsItem this array should hold all items details
// sadly it always have 1 element instead of the full content of my cart :(
$orderTotal = $details->PaymentDetails->OrderTotal;
$PaymentDetails= new PaymentDetailsType();
$PaymentDetails->OrderTotal = $orderTotal;
//
Some stuff with payment details
//
$DoECRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
$DoECRequest = new DoExpressCheckoutPaymentRequestType();
$DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails;
$DoECReq = new DoExpressCheckoutPaymentReq();
$DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
$DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
Do i miss a step or call a bad function. Because i tried to print_r every variable i came across and the full content of my cart was nowhere to be found. I find this strange since the 'orderTotal' of the transaction match with my original cart. I could store my original order during the SetExpressCheckout step but since paypal already have those values i find it redundant.
As a last resort I did found the content of my cart using $paypalService->getLastRequest() but seriously this is the raw XML returned by paypal and the api should be parsing it properly :(.
Thanks for reading
I had this exact same issue - while the XML returned by PayPal is fine, their PHP SDK doesn't parse it properly, so you can only ever see the last item in GetExpressCheckout.
I've posted a fix for this problem in an issue on PayPal's GitHub, please check it out:
https://github.com/paypal/SDKs/issues/37

Magento Get Last Order Id on Payment Info Block Email

See above is a picture of new order acknowledgement email of Magento.
On the website we're developing we use Fontis Australia extension (http://www.magentocommerce.com/magento-connect/fontis-australia.html) to implement BPay payment method. The extension works ok, except that on the order acknowledgement email, the Email ref always show 000000.
I try to look at it and see that the ref number generated need the order ID as input to generate the correct ref number.
The extension use this code to get the last order number on payment info block:
$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
I try to use and print the result from other controller, it shows the correct order number. But seems that for the payment info block on email, the order number info can't be retrieved. Actually the same block also called out on the checkout success page, and it shows correctly.
Can somebody suggest other way to get the last order id on payment info block on Magento Email?
In info template you can use $order = $this->getInfo()->getOrder(); to get Mage_Sales_Model_Order object. Then you can get current order id by $order->getData('increment_id').
But with this code, you get error in checkout process, because $this->getInfo() returns other model.
So dirty solution, that works for me without errors, is:
$info = $this->getInfo();
if ($info instanceof Mage_Sales_Model_Order_Payment) {
$order = $info->getOrder();
echo $order->getData('increment_id'));
}