• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2592
  • Last Modified:

How to make Api calls from Magento to third party API

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
rafique12
Asked:
rafique12
  • 6
  • 4
2 Solutions
 
Richard DavisSenior Web DeveloperCommented:
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
 
Eddie ShipmanAll-around developerCommented:
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
 
rafique12Author Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Eddie ShipmanAll-around developerCommented:
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
 
rafique12Author Commented:
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
 
rafique12Author Commented:
I still get the error though!

Fatal error: Call to a member function getStreet() on a non-object in
0
 
rafique12Author Commented:
I'm actually trying to export customer information using the API to a third party platform
0
 
Eddie ShipmanAll-around developerCommented:
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
 
Eddie ShipmanAll-around developerCommented:
Also, you can do this to get all street lines at once:

$billingAddress->getData('street');
$billingAddress->getStreetFull();
$billingAddress->getStreet(-1);
0
 
rafique12Author Commented:
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
 
rafique12Author Commented:
Thanks for the help guys!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now