Link to home
Start Free TrialLog in
Avatar of rafique12
rafique12

asked on

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.
SOLUTION
Avatar of Richard Davis
Richard Davis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rafique12
rafique12

ASKER

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.
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.
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

I still get the error though!

Fatal error: Call to a member function getStreet() on a non-object in
I'm actually trying to export customer information using the API to a third party platform
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

Also, you can do this to get all street lines at once:

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