Solved

How to make Api calls from Magento to third party API

Posted on 2013-01-11
11
1,999 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
echo paypal data on screen 5 54
UPDATE query not working in mysqli php 8 52
PHP AJAX Wordpress 9 21
Math Equation 23 88
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

822 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