Post sales order to 3rd party api with reply - magento

Basically I'm trying to send sales orders to third-party API from magento and receive a notification whether the order has been accepted or not.
I have created users and rolls for the rest system with api user and password And I have read multiple Forum posts but can't seem to find where to go from here I have a piece of code which I've been given by the third- API to connect to their API here is the info below
Post example (fixed)
<form method="post" action="http://iconnect.ibacstel.com/submitorder.php">
<input name="api_key" value="Your API Key" />
<input name="api_password" value="Your API Password" />
<input name="notify_url" value="Notify URL" /> <!-Notify url is your websites url where you would like to get notification from ibacstel api -->
<input name="receipt_header" value="Header Line1%%123 Street Address, City, Zip Code" />
<input name="receipt_footer" value="Thanks for your custom..." />
<input name="printer_id" value="Your printer ID" />
<input name="order_id" value="OrderID" />
<input name="currency" value="Currency" /><!--ex. USD/GBP -->
<input name="order_type" value="1" /><!--Delivery=1, Pick up=2, Reservation=3-->
<input name="payment_status" value="6" /><!--Paid=6, Not Paid=7-->
<input name="payment_method" value="Payment Method" />
<input name="delivery_time" value="18:30 17-09-10 " /><!--Format=HH:MM DD-MM-YY-->
<input name="auth_code" value="Payment authorization code" />
<input name="cat_1" value="Category 1" />
<input name="item_1" value="Item Name 1" />
<input name="desc_1" value="Item description 1" />
<input name="qnt_1" value="1" />
<input name="price_1" value="10.50" />
<input name="cat_2" value="" />
<input name="item_2" value="Item Name 2" />
<input name="desc_2" value="Item description 2" />
<input name="qnt_2" value="1" />
<input name="price_2" value="10.50" />
<input name="cat_3" value="Category 2" />
<input name="item_3" value="Item Name 3" />
<input name="desc_3" value="Item description 3" />
<input name="qnt_3" value="1" />
<input name="price_3" value="10.50" />
---------
You can place more items here using above format.
Please note that you don't need to send category name for the items after first item if the category name is same and if you put all same category items consecutively.
---------
<input name="deliverycost" value="3.50" />
<input name="card_fee" value="0.50" />
<input name="extra_fee" value="1.50" />
<input name="total_discount" value="4.50" />
<input name="total_amount" value="56.50" /><!--Grand Total -->
<input name="cust_name" value="Customer Name" />
<input name="cust_address" value="Customer address" />
<input name="cust_phone" value="Phone number" />
<input name="cust_instruction" value="Special instruction" />
<input name="isVarified" value="4" /><!-Verified=4, Not verified=5 -->
<input name="num_prev_order" value="Number of previous order" />
---------settings---------
<input name="apply_settings " value="1" />
<input name="auto_print" value="1" />
<input name="auto_accept" value="1" />
<input name="enter_delivery_time" value="1" />
<input name="time_input_method" value="2" />
<input name="time_list" value="0-5-10-15-20-25-30-35-40-45-50-55-60" />
<input name="extra_line_feed" value="3" />
<input type="submit" value="Submit" />
</form>
Post example (free style)
<form method="post" action="http://iconnect.ibacstel.com/submitorderfreestyle.php">
<input name="api_key" value="Your API Key" />
<input name="api_password" value="Your API Password" />
<input name="notify_url" value="Notify URL" /> <!-Notify url is your websites url where you would like to get notification from ibacstel api -->
<input name="receipt_header" value="Header Line1%%123 Street Address, City, Zip Code" />
<input name="receipt_footer" value="Thanks for your custom..." />
<input name="printer_id" value="Your printer ID" />
<input name="order_id" value="OrderID" />
<input name="currency" value="Currency" /><!--ex. USD/GBP -->
<input name="delivery_time" value="18:30 17-09-10 " /><!--Format=HH:MM DD-MM-YY-->
<input name="print_data" value="Line 1/rLine 2%%Line 3/-" />
<input name="total_amount" value="56.50" /><!--Grand Total -->
---------settings---------
<input name="apply_settings " value="1" />
<input name="auto_print" value="1" />
<input name="print_only" value="0" />
<input name="auto_accept" value="1" />
<input name="enter_delivery_time" value="1" />
<input name="time_input_method" value="2" />
<input name="time_list" value="0-5-10-15-20-25-30-35-40-45-50-55-60" />
<input name="extra_line_feed" value="3" />
<input type="submit" value="Submit" />
</form>
Success response
<response>
<status>OK</status>
<details>
<msg>Order has been stored successfully</msg>
</details>
</response>
Error response
<response>
<status>FAILED</status>
<details>
<error> Authentication failed </error>
<error> Other errors...</error>
</details>
</response>
Update notification format
When printer sends a callback response to API the API sends a notification to the Provided Notify URL with order
In your notification url you will get notification regarding the status of the order, all the information will be submitted via post method which will allow you to grab information easily.
Post variables:
"printer_id" = Printer ID
"order_id" = Order ID
"status" = (1=accepted,2=rejected)
"msg" = message from printer
"delivery_time" = confirmed delivery time from printer
"manual_update" = (1=manual update identifier)
"booking" = (1=manage booking identifier)
Please note that you will not get the notification while you are sending order to API even if the notify URL is same as where you are sending order to API. API will send response later automatically when the order will be accepted/rejected from printer to that Notify URL you provided with order. So we recommend you to use separate URL/file to send order to API and receive notification from API to avoid confusion.
Example in PHP
Lets say you are sending order the URL of your site www.example.com/sendorder.php to API
So you need to write necessary code on sendorder.php to send order information from your site to API. I am not telling you the details here how to send order to API. Please check our example html form above to send order information to API.
Lets say you have used the value of notification URL field www.example.com/receivenotification.php in orders sending form like <input name="notify_url" value="www.example.com/receivenotification.php" /> then iConnect API will send notification to www.example.com/receivenotification.php as soon as API get response from printer when an order will be accepted/rejected after printing. Here is the example code to grab the information from API notification need to be placed on receivenotification.php file.
<?php
$printer_id = $_REQUEST['printer_id'];
$order_id = $_REQUEST['order_id'];
$order_status = $_REQUEST['status'];
$message = $_REQUEST['msg'];
$delivery_time = $_REQUEST['delivery_time'];
if($order_status==1){
//order has been accepted from printer
//do your necessary task for accepted order like update databse, send email to customer to inform him that his order has been accepted and will be delivered on returned delivery time (variable $delivery_time).
}
else{
//order has been rejected from printer
//do your necessary task for rejected order like update databse, send email to customer to inform him that his order has been rejected for the returned reason (variable $message).
}
?>
Basically I need to know where to put this code and or what file I have to modify or create in order to do this. Thanks in advance
So i have created all of the files that you detailed out and i have put my 3rd party code where you stated it to go but, isnt working, heree is my thirdparty.php file contents maybee you will se where im going wrong.
<?php
class Bh_ZeroSubtotalpaymentmethod_Model_Thirdparty {
public function automatic(Varien_Event_Observer $observer)
{
$orderIds = $observer->getEvent()->getOrderIds();
if (empty($orderIds) || !is_array($orderIds)) {
return;
}
foreach($orderIds as $eachOrderId){
$order = Mage::getModel('sales/order')->load($eachOrderId);
<form method="post" action="http://iconnect.ibacstel.com/submitorderfreestyle.php">
<input name="api_key" value="******" />
<input name="api_password" value="************" />
<input name="notify_url" value="Notify URL" /> <!-Notify url is your websites url where you would like to get notification from ibacstel api -->
<input name="receipt_header" value="Header Line1%%Take, City, Zip Code" />
<input name="receipt_footer" value="Thanks for your custom..." />
<input name="printer_id" value="Your printer ID" />
<input name="order_id" value="OrderID" />
<input name="currency" value="Currency" /><!--ex. USD/GBP -->
<input name="delivery_time" value="18:30 17-09-10 " /><!--Format=HH:MM DD-MM-YY-->
<input name="print_data" value="Line 1/rLine 2%%Line 3/-" />
<input name="total_amount" value="56.50" /><!--Grand Total -->
---------settings---------
<input name="apply_settings " value="1" />
<input name="auto_print" value="1" />
<input name="print_only" value="0" />
<input name="auto_accept" value="1" />
<input name="enter_delivery_time" value="1" />
<input name="time_input_method" value="2" />
<input name="time_list" value="0-5-10-15-20-25-30-35-40-45-50-55-60" />
<input name="extra_line_feed" value="3" />
<input type="submit" value="Submit" />
</form>
Success response
<response>
<status>OK</status>
<details>
<msg>Order has been stored successfully</msg>
</details>
</response>
Error response
<response>
<status>FAILED</status>
<details>
<error> Authentication failed </error>
<error> Other errors...</error>
</details>
</response>
}
return $this;
}
}
is this correct? also can you please take a look at the third party code and tell me weather this will work in magento or do i have to translate this into a different language? Thankks

Magento have an interesting feature Event-obsever and trigger and run some code using observer.
For example,nagento event list http://www.nicksays.co.uk/magento-events-cheat-sheet-1-7/
for frontend after place an order run some
Create an extension using
create config.xml under app/code/local/Bh/ZeroSubtotalpaymentmethod/etc
<?xml version="1.0" ?>
<config>
<modules>
<Bh_ZeroSubtotalpaymentmethod>
<version>1.0.1</version>
</Bh_ZeroSubtotalpaymentmethod>
</modules>
<global>
<models>
<zerosubtotalpaymentmethod>
<class>Bh_ZeroSubtotalpaymentmethod_Model</class>
</zerosubtotalpaymentmethod>
</models>
</global>
<frontend>
<events>
<checkout_onepage_controller_success_action>
<observers>
<create_thridparty_order>
<class>zerosubtotalpaymentmethod/thirdparty</class>
<method>automatic</method>
</create_thridparty_order>
</observers>
</checkout_onepage_controller_success_action>
</events>
</frontend>
<adminhtml>
<events>
<checkout_submit_all_after>
<observers>
<create_thridparty_order>
<class>zerosubtotalpaymentmethod/thirdparty</class>
<method>automatic</method>
</create_thridparty_order>
</observers>
</checkout_submit_all_after>
</events>
</adminhtml>
</config>
**** And then create Thirdparty.php under app/code/local/Bh/ZeroSubtotalpaymentmethod/Model/**
<?php
class Bh_ZeroSubtotalpaymentmethod_Model_Thirdparty {
public function automatic(Varien_Event_Observer $observer) {
$orderIds = $observer->getEvent()->getOrderIds();
if (empty($orderIds) || !is_array($orderIds)) {
return;
}
foreach ($orderIds as $eachOrderId) {
$order = Mage::getModel('sales/order')->load($eachOrderId);
//right our third party code
client = new Zend_Http_Client();
$client->setUri('http://iconnect.ibacstel.com/submitorderfreestyle.php');
$client->>setParameterPost(array(
'api_key' => 'yourapi',
'apikey' => 'xxxx',
'message' => $message,
'order_id' => $order_id,
...//more params
));
$response = $client->request('POST');
// Yet another way of preforming a POST request
$client->setMethod(Zend_Http_Client::POST);
if (!$response->isSuccessful()) {
Mage::log($response);
}
}
return $this;
}
}
Also.create under Bh_ZeroSubtotalpaymentmethod.xml
app/etc/modules/
<?xml version="1.0" ?>
<config>
<modules>
<Bh_ZeroSubtotalpaymentmethod>
<active>true</active>
<codePool>local</codePool>
</Bh_ZeroSubtotalpaymentmethod>
</modules>
</config>

Related

Html Editor Template

I have a editor template DisplayConfig. In DisplayConfig
#model string
<input id="#(Model)_DisplayOrder" class="DisplayTypeConfigurator" type="number" />
<input id="#(Model)" class="DisplayTypeConfigurator" type="checkbox" />
I want to call this template in my view and send string so i get different id for every textbox.
In my view
#Html.Editor("Tab_Info_Product", "DisplayConfig")
I do not want to send the value through my model.
I want the result like
<input id="Tab_Info_Product_DisplayOrder" class="DisplayTypeConfigurator" type="number" />
You should use #Html.IdForModel() to construct the ids of your <input> tags.
<input id="#Html.IdForModel()_DisplayOrder" class="DisplayTypeConfigurator" type="number" />
<input id="#Html.IdForModel()" class="DisplayTypeConfigurator" type="checkbox" />

C# Launching Yodlee FastLink

I'm doing a project to launch yodlee fastlink. I was able to get the token and userSession and trying the below codes. I'm only getting "Cannot POST resource". I'm trying to find a more detailed/simpler documentation. Any help would be appreciated.
<form action="https://node.developer.yodlee.com/authenticate/restserver" method="post" name="rsessionPost" id="rsessionPost" target="yodleeIframe">
<input style="visibility: hidden" type="text" name="rsession" placeholder="rsession" value="08312016_0:149676f79ace306255a2c7827f9db590ccabd7350ad5d952f31fc503675bba9ec522728c213a9e5c3e98bd8ceff795c88f9a6f80040a68ce325ae54759f6e504" id="rsession" /><br />
<input style="visibility: hidden" type="text" name="app" placeholder="FinappId" value="10003600" id="finappId" /><br />
<input style="visibility: hidden" type="text" name="redirectReq" placeholder="true/false" value="true" /><br />
<input style="visibility: hidden" type="text" name="token" placeholder="token" value="e59f51a169f52925cd715a945630686e59667d2d1fae511fd50b4e292a8e7342" id="token" /><br />
<input type="submit" name="submit" />
</form>
It seems like there is a forward slash '/' missing at the end of the URL.
Please put it there and submit the form you should be able to access Fastlink.
"https://node.developer.yodlee.com/authenticate/restserver/"

HTML params as array

I use Gaelyk framework on Google AppEngine.
from HTML form I need to get params in exact sequence.
Order of params is very important from my application.
I have HTML Form contans:
<input type="hidden" name="coins" value="50" />
<input type="hidden" name="coins" value="40" />
<input type="hidden" name="coins" value="30" />
<input type="hidden" name="coins" value="20" />
<input type="hidden" name="coins" value="10" />
After form submiting I got array:
// [50,40,30,20,10]
print params.coins
The array is in correct order, but can I depend on this behavior?
or if I need exact order, I need to write:
<input type="hidden" name="coins[0]" value="50" />
<input type="hidden" name="coins[1]" value="40" />
<input type="hidden" name="coins[2]" value="30" />
<input type="hidden" name="coins[3]" value="20" />
<input type="hidden" name="coins[4]" value="10" />
In servlet I got map:
// ['coins[3]':20,'coins[0]':50,'coins[1]':40,'coins[2]':30,'coins[4]':10]
print params
What is the correct solution?
If the second solution is correct, what is the best solution for obtaining Array from Maps?
Thanks a lot
Tom
According to this similar question, so long s the browser sticks to the specification, then the order can be relied upon.
If the browser doesn't stick to the specification obviously, you'll need to go with option[2]

How can I redirect a customer back to my website after a successful payment with Google Checkout?

I am doing a shopping cart with Google Checkout. I integrated Paypal already like below:
<form name="frmpay" method="post" action="success.php">
<input type="hidden" name="business" value="" />
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="image_url" value="https://www.paypal.com/en_US/i/btn/x-click-but22.gif" />
<input type="hidden" name="return" value="success.php" />
<input type="hidden" name="cancel_return" value="error.php" />
<input type="hidden" name="currency_code" value="GBP" />
<input type="hidden" name="lc" value="UK" />
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="item_name" value="<?=$res_item[name]?>" />
<input type="hidden" name="amount" value="<?=$_SESSION['amt']?>" />
<?php /*?><input type="hidden" name="shipping" value="<?=$_POST["shipping"]?>" /><?php */?>
<input type="hidden" name="quantity" value="1" />
</form>
How can I integrate Google Checkout like this? How can I return success page after payment in Google checkout? What is the input type for redirect url after successful payment in Google Checkout? I tried a lot for this but I did not get anywhere.
Here is my code:
<form method="POST" action="https://sandbox.google.com/checkout/api/checkout/v2/checkoutForm/Merchant/REPLACE_WITH_YOUR_SANDBOX_MERCHANT_ID" accept-charset="utf-8">
<!-- No product -->
<!-- No tax code -->
<!-- No shipping code -->
<input type="hidden" name="_charset_" />
<!-- Button code -->
<input type="image"
name="Google Checkout"
alt="Fast checkout through Google"
src="http://sandbox.google.com/checkout/buttons/checkout.gif?merchant_id=REPLACE_WITH_YOUR_SANDBOX_MERCHANT_ID&w=180&h=46&style=white&variant=text&loc=en_US"
height="46"
width="180" />
</form>
There is no automatic re-direct for the buyer after the Google Checkout transaction finishes. However, you can provide a link that the user can click and get back to your site after completing the order.
See the continue_url paramenter:
http://code.google.com/apis/checkout/developer/Google_Checkout_HTML_API_Parameter_Reference.html#tag_continue-shopping-url
I have the same problem.
My rough variant is to sell a link to a user, and after the user has successfully paid for the link, he will be redirected to the "thank you" page on Google Checkout, where he will see my link and a message from me, then he clicks on the link and gets back to my site
A link looks like mysite.com/orderhasbeenpayd/1342
but as I said it is a rough variant

PayPal discount can't make it work

I'm trying to setup a discount for a the whole cart using PayPal + Codeigniter, I got this working withouth the discounts.
As far as I've read the only thing that I would need to do is set a hidden field discount_amount_cart as I saw here
Here is my form:
<form method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr" name="paypal_form">
<input type="hidden" name="rm" value="2" />
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="currency_code" value="EUR" />
<input type="hidden" name="business" value="biz_1271300483_biz#xxxx.xx" />
<input type="hidden" name="return" value="http://xxxxxx.com/website/pt/paypal/success/8/4c237a03897e0" />
<input type="hidden" name="cancel_return" value="http://xxxxxxx.com/website/pt/paypal/cancel/8/4c237a03897e0" />
<input type="hidden" name="notify_url" value="http://xxxxxx.com/website/pt/paypal/ipn" />
<input type="hidden" name="custom" value="" />
<input type="hidden" name="no_shipping" value="1" />
<input type="hidden" name="cpp_header_image" value="http://xxxxxxxxx.com/images/logo.png" />
<input type="hidden" name="image_url" value="http://xxxxxxxxx.com/images/logo.png" />
<input type="hidden" name="invoice" value="4c237a03897e0" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="discount_rate_cart" value="10.00" />
<input type="hidden" name="first_name" value="Foo Bar" />
<input type="hidden" name="city" value="xxxx" />
<input type="hidden" name="address1" value="xxxxxx" />
<input type="hidden" name="zip" value="xxxxxx" />
<input type="hidden" name="lc" value="pt" />
<input type="hidden" name="email" value="xxxxx#xxx.pt" />
<input type="hidden" name="country" value="PT" />
<input type="hidden" name="item_name_1" value="Cloud Hosting WIN Business 25GB" />
<input type="hidden" name="item_number_1" value="200.00000003" />
<input type="hidden" name="amount_1" value="156" />
<input type="hidden" name="quantity_1" value="1" />
<input type="hidden" name="tax_rate_1" value="20" />
<p><input type="submit" name="pp_submit" value="Pagar" class="submit" /></p>
</form>
But when I "post" the fields the discount line won't appear, do I need to activate something in the merchant account, am I doing something wrong?
Cheers
Got it,
From the PayPal documentation:
When you use consolidated discount amounts, you should specify a consolidated tax value in tax_cart. If you do not specify a tax value and your profile specifies a tax rate, your profile tax rate is applied after the consolidated discount value is applied.
So I need to define my "global" tax amount for the cart with tax_cart.
The name of your discount input appears to be wrong:
<input type="hidden" name="discount_rate_cart" value="10.00" />
should be:
<input type="hidden" name="discount_amount_cart" value="10" />
Use discount_amount_cart to charge a
single discount amount for the entire
cart.
Use discount_amount_x to set a
discount amount associated with item x
Use discount_rate_cart to charge a
single discount percentage for the
entire cart.
discount_rate_cart - Applies to
entire cart however, this variable
will only work with the "Upload"
Method. Not the standard Add to Cart
variables.
This variable will be ignored if you
are including any individual sales tax
amount or rate in your upload method
code. This is because the sales tax
needs to be calculated after the
discount is applied to your items
therefore, the discount is applied to
the item Subtotal, not the Total.
Note, If you just using the standard
Add to Cart buttons, there no Discount
variables for the entire cart. as
they "only" apply a Discount to an
individual item.

Resources