Solved

How to make Api calls from Magento to third party API

Posted on 2013-01-11
11
1,911 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
  • 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now