Solved

How to make Api calls from Magento to third party API

Posted on 2013-01-11
11
2,139 Views
Last Modified: 2016-03-02
I am looking for a way to make four API calls from Magento using a third party API.

I can't find any good documentation on how to set this up on Magento in terms of file structure. For example, should I create a module? or simply place the files in a folder under my Magento directory?

I would really like just a brief explanation as to how I need to get this started so I can make these calls to a third party system:

1) Log into the BS API - API call LoginRequest()

2) Create a new customer account - API call requestCreateCustomer()

3) Start a customers purchase of an offer - API call requestRegisterCustomerOfferPurchase()

4) Verify sucessful card capture, and confirm the purchase of the offer by the customer - API call  requestCompleteCustomerOfferPurchase()

I have all the relevant documentation but I am unsure about the basic file structure in rder for this to work. Any ideas or links to a tutorial will be much appreciated.
0
Comment
Question by:rafique12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 12

Assisted Solution

by:adrian_brooks
adrian_brooks earned 250 total points
ID: 38773047
I don't know the first thing about Magento, but I do know that if someone is going to help you, it will likely involve using PHP's cURL functions as this is the method most commonly used for making calls to remote systems (API's) using GET or POST methods over an HTTP protocol.

If your third party supports SOAP or REST, then those are the other two remaining methods that can be used. So, as I stated, I know zip about Magento, but I hope that what I did provide will at least give you a general direction from which to kick off further research.

~AB
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 250 total points
ID: 38774584
Did you not check out the Magento API documentation? Heres sample code showing how to create a customer using the API:
http://www.magentocommerce.com/api/soap/customer/customer.create.html
0
 

Author Comment

by:rafique12
ID: 38774603
Thankyou for you response! I have been making some progress and was about to post another question. I followed this tutorial http://www.excellencemagentoblog.com/magento-create-custom-payment-method-api-based

but I am getting this error

Fatal error: Call to a member function getStreet() on a non-object in

I think this is definitely what I need but I'm a bit stuck getting it to work.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 26

Expert Comment

by:EddieShipman
ID: 38774947
Should be getStreet(0) or getStreet(1), etc depending upon which one you want.
Also, make sure you have a valid address object before calling it.

I didn't see that code in any of that tutorial.
0
 

Author Comment

by:rafique12
ID: 38774958
Thankyou for the reply, its actually code from the module itself.

<?php 
	$session = Mage::getSingleton('checkout/session');
	$orderIncrementId = $session->getLastRealOrderId();
	$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
	$billingaddress = $order->getBillingAddress();
	$shippingaddress = $order->getShippingAddress();
	$currencyDesc = Mage::app()->getStore()->getCurrentCurrencyCode();
	$totals = number_format($order->getGrandTotal(), 2, '.', ''); 
	$address = $billingaddress->getStreet();
	$address1 = $shippingaddress->getStreet();
	$data = array(
   	'Merchant_Id' => trim(Mage::getStoreConfig('payment/pay/api_username')),
	'Amount' => $totals,
	'billing_cust_name' =>$order->getCustomerFirstname(), 
	'billing_last_name'=>$order->getCustomerLastname(),
	'billing_cust_tel_No' => $billingaddress->getTelephone(),
	'billing_cust_email'=>$order->getCustomerEmail(),
	'billing_cust_address'=>$address[0] . ' '.$address[1],
	'billing_cust_city'=>$billingaddress->getCity(),
	'billing_cust_country'=>$billingaddress->getCountryId(),
	'billing_cust_state'=>$billingaddress->getRegion(),
	'billing_cust_zip' =>$billingaddress->getPostcode(),
	'delivery_cust_name' =>$shippingaddress->getCustomerFirstname(),
	'delivery_last_name'=>$shippingaddress->getCustomerLastname(),
	'delivery_cust_tel_No' => $shippingaddress->getTelephone(),
	'delivery_cust_email'=>$shippingaddress->getCustomerEmail(),
	'delivery_cust_address'=>$address1[0] . ' '.$address1[1],
	'delivery_cust_city'=>$shippingaddress->getCity(),
	'delivery_cust_country'=>$shippingaddress->getCountryId(),
	'delivery_cust_state'=>$shippingaddress->getRegion(),
	'delivery_cust_zip' =>$shippingaddress->getPostcode(),
	'Order_Id' => $order->getIncrementId(),
	'TxnType' => 'A',
	'actionID' => 'TXN',
	'Currency' => 'GBP',
	);
	
?>
<form action="https://world.ccavenue.com/servlet/ccw.CCAvenueController" method="post" id="redirectpay">
	<?php foreach($data as $key => $value):	?>
		<input type='hidden' name='<?php echo $key?>' value='<?php echo $value;?>' />
	<?php endforeach;?>
	<input type="submit" value='Buy Now'/> 
</form>

	<?php echo $this->__('If Page Doesn\'t Redirect In 5 Sectonds, Please press Buy button');?>
	<script type="text/javascript">
	function myfunc () {
	var frm = document.getElementById("redirectpay");
	frm.submit();
	}
	window.onload = myfunc;
	</script>

Open in new window

0
 

Author Comment

by:rafique12
ID: 38774968
I still get the error though!

Fatal error: Call to a member function getStreet() on a non-object in
0
 

Author Comment

by:rafique12
ID: 38775073
I'm actually trying to export customer information using the API to a third party platform
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 38775331
Which call to getStret() is giving you the error? Could it be that you don't have a ShippingAddress? If the order only has a BillingAddress, meaning they selected shipto same, then I don't think the ShippingAddress would be filled.


rework your code like this and see if the error goes away:

        if(isset($billingaddress)) {
	    $address = $billingaddress->getStreet();
        }
        if(isset($shippingaddress)) {
            $address1 = $shippingaddress->getStreet();
        }

Open in new window

0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 38775352
Also, you can do this to get all street lines at once:

$billingAddress->getData('street');
$billingAddress->getStreetFull();
$billingAddress->getStreet(-1);
0
 

Author Comment

by:rafique12
ID: 38788801
Sorry, I haven't given up on this question I'm still trying to find the correct method. I will post back as soon as.
0
 

Author Closing Comment

by:rafique12
ID: 38839443
Thanks for the help guys!
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article discusses how to implement server side field validation and display customized error messages to the client.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question