Active Merchant Integrations (off site payments) [closed] - ruby-on-rails

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
My original question (below) was perhaps too specific, so I'm going to ask something more general!
Can anyone point me in the direction of a tutorial, example or documentation on using Active Merchant Integrations to support an offsite payment gateway?
Active Merchant's rdoc lists all of the following as supported offsite payment gateways but I haven't found any tutorials or examples on how to use ActiveMerchant::Billing::Integrations
2 Checkout
Banca Sella GestPay
Chronopay
Direct-eBanking
DirecPay
HiTRUST
Moneybookers
Nochex
PayPal Website Payments Standard
SagePay Form
Valitor
WorldPay
As good as they may be, peepcode and rails casts only consider gateways, not integrations.
Many thanks!
My company is moving from PayPal Express Checkout to WorldPay Business
Gateway (Hosted Payment Page). We're using Rails and Active Merchant.
Does Active Merchant support WorldPay Business Gateway (Hosted Payment Page)? I think it does, judging by the rdoc
What arguments must I supply to ActiveMerchant::Billing::Integrations::WorldPay.new ?
Thanks

I made a simple app to demonstrate how off-site payments for Worldpay and Rails/Activemerchant can work together.
Demo Rails App-
https://github.com/daemonsy/Worldpay-Rails--Off-Site--Integration-Example
For World Pay hosted payment, basically a post to their payment URL is required. Add test- to secure.worldpay.com for testing mode. WP requires amount, currency, installation ID and cartId to render the page to the customer.
<form action="https://test-secure.worldpay.com/wcc/purchase" method=POST>
<!-- This next line contains the testMode parameter - it specifies that the submission is a test submission -->
<input type="hidden" name="testMode" value="100">
<!-- This next line contains a mandatory parameter. Put your Installation ID inside the quotes after value= -->
<input type="hidden" name="instId" value="Your installation ID ">
<!-- Another mandatory parameter. Put your own reference identifier for the item purchased inside the quotes after value= -->
<input type="hidden" name="cartId" value="Your ID for the product ">
<!-- Another mandatory parameter. Put the total cost of the item inside the quotes after value= -->
<input type="hidden" name="amount" value="The cost of the product ">
<!-- Another mandatory parameter. Put the code for the purchase currency inside the quotes after value= -->
<input type="hidden" name="currency" value="currency code e.g. GBP, USD ">
<!-- This creates the button. When it is selected in the browser, the form submits the purchase details to us. -->
<input type=submit value=" Buy This ">
Source: http://www.worldpay.com/support/kb/bg/htmlredirect/rhtml.html
This creates a simple button that carries your order to World Pay where the customer will enter credit card details and complete the purchase. I've embedded the above code in the show page of an orders controller. e,g, <input type="hidden" name="amount" value="<%=#order.amount"%>>. So you can click buy this after submitting the order. There are many ways to achieve a POST to World Pay.
After which, World Pay can show a shopper response page, send you payment response etc. For payment response to work, you can setup the payment response callback URL to one of your controllers. e.g. =>http://mysite.com/payment-backend
This will be a POST request so you have to setup your controller to handle it. This is where Activemerchant kicks in. For example,
class BackendsController < ApplicationController
include ActiveMerchant::Billing::Integrations
protect_from_forgery :except=>[:worldpay_return]
#in routes => match '/payment-backend'=>'backends#worldpay_return'
def worldpay_return
notification = WorldPay::Notification.new(request.raw_post)
order = Order.find(notification.item_id)
if notification.acknowledge
begin
if notification.complete?
order.status = 'success'
end
rescue
order.status = "failed"
raise
ensure
order.save
end
end
render :text =>"Order status for #{order.id} is #{order.status}"
end
end
So the Notification object will read the params in request.raw_post and set them up the an object where you can query. I found the active merchant docs useful in telling what return params are mapped by it.
Note that this controller is a very crude example. World Pay provides a few methods for you to validate the response and this is supported by Active Merchant.
ActiveMerchant Docs on WorldPay::Notifications
http://rdoc.info/github/Shopify/active_merchant/master/ActiveMerchant/Billing/Integrations/WorldPay
World Pay Payment Response Docs
http://www.worldpay.com/support/kb/bg/paymentresponse/payment_response.html

Related

Passing a list from a view to a controller? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I'm a relatively new Rails developer with a heavy Java/C# background and I'm trying to pass multiple time ranges from my view to my controller. For instance, the user could select the time range 9:00am to 11:00am as well as 2:00pm to 4:00pm. The first thing to came to mind was a list of times or a list of key value pairs so that I know when a time range starts and ends. I'm having trouble figuring out how to pass this information to my Rails controller though.
Is there an ideal Rails way of passing a list to a controller?
From Rails Guide http://guides.rubyonrails.org/action_controller_overview.html
request
GET /mytime?t[]=1&t[]=2&t[]=3
in view
<form method="GET" action="mytime">
<select multiple name="t[]">
<option value="1">1:00pm</option>
<option value="2">2:00pm</option>
<option value="3">3:00pm</option>
</select>
</form>
or
<form method="GET" action="mytime">
<input type="text" name="t[]">
<input type="hidden" name="t[]" value="11">
</form>
#in mytime_controller.rb
def index
params[:t] # return Array of values
end
You pass information from a view to a controller via http query string ('get') or form data ('post').
I would consider multi-select dropdown for this case.
Instead of dropdown i suggest you should create a cool for using some jquery plugin that will improve your application's user experience and yes create a rails form and submit it then you can have information in your controller.
Now is you are saving these selected time, that i think you should do then create a model if you haven't already and use form_for else your can use form_tag for your rails application.
Visit Here and find some time picker that suits you need.

Use Eventbrite API to create ticket order on 3rd party website

Here's my flow - is this possible with eventbrite APIs? if yes, which ones specifically? I've tried looking through current listed apis and don't see how I can create the order and then pass it on to the eventbrite site for processing the order.
I am trying to find an API whereby I would pass-in discount code along with #of tickets and eventID from my website to eventbrite site. Is there a good example for this?
The workflow that I want to implement is:-
Step 1 On My Website, there is eventbrite Ticket Widget button along with Ticket Previews (http://developer.eventbrite.com/doc/widgets/#button) on the event page
Step 2: Clicks on Buy Tickets/Register/ buttons (from the widget)
Step 3: redirect to eventbrite website with eventID, user-elgible-discount-code, #of-tickets-selected-by-user
Step 4: eventbrite system processes the ticket order as specified in the api call (along with price/discount, qty, eventId, etc.) on eventbrite.com site
Any help appreciated.
Thanks,
Jatin
You can leave out the widget altogether and post directly to the EB checkout page.
For example:
<form action="http://www.eventbrite.co.uk/orderstart?ebtv=C" method="post">
<input type="hidden" name="eid" value="[EVENT_ID]">
<input type="text" name="quant_[TICKET_ID]_None" value="[QUANTITY]" />
<input type="text" name="discount" value="[DISCOUNT_CODE]" />
<input type="hidden" name="has_javascript" value="1">
<input type="submit" />
</form>
I wouldn't have thought this method is officially supported but it seems to work at the moment.

PayPal how to set the subtotal attribute from the application

I'm developing a web application based on JSF 2.0. The application automatically generates a quote to sell a service so, the subtotal it's not predictable.
I would like to integrate PayPal Payments but I need to set the subtotal value in a dynamic way. I succeeded in doing payments of a fixed amount through the payPal sandbox using the standard integration of the HTML button. I also tried to add to the form that contains the generated button the subtotal value but it doesn't seem to work.
Something like:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick"></input>
<input type="hidden" name="hosted_button_id" value="3V8S6DNHUQ58C"></input>
<input type="hidden" name="subtotal" value="88"> </input>
<input type="image"
src="https://www.sandbox.paypal.com/it_IT/IT/i/btn/btn_buynow_LG.gif"
name="submit"
alt="PayPal - Il metodo rapido, affidabile e innovativo per pagare e farsi pagare."></input>
<img alt="" border="0"
src="https://www.sandbox.paypal.com/it_IT/i/scr/pixel.gif" width="1"
height="1"></img>
</form>
Is there a way to set subtotal value from the application with HTML standard integration, preferentially getting the value from a bean property?
Do I have to use a more advanced way for the integration? Thanks for help, as usual.. :)
The button you're currently using is a hosted button. As such, you cannot dynamically adjust it the way you want to.
You would have to edit your button and disable the "save at PayPal" option in order to make it a non-hosted button. This way you would have direct access to the actual request parameters and you could adjust their values accordingly.
That said, it's not very secure because then users can see your button code, copy it, and adjust it before making a payment with it.
I would recommend you use the Express Checkout API instead. This consists of SetExpressCheckout, GetExpressCheckoutDetails, and DoExpresscheckoutPayment. This is a little bit more involved because you're working with web services, but it opens you up to customize it however you need and is secure.

Clarifying POST-ing to a site

Say I were to post to a site using www.mysite.com?user=myuser does that simulate the submit button that is associated with that form? If so, what happens if there are a number of submit buttons in the form?
Also, if that button's html is like so <input name="button" class="button" type="button" value="Save" onclick="javascript: submit()" disabled> with the "disabled" attribute, does that mean I can't POST www.mysite.com?user=myuser/won't work?
<form name="Form" method="post" action="/thisAction.do">
<input type="text" name="inquiryNo" maxlength="11" value="" onkeyup="javascript: checkNo()">
<input name="buttonInquire" class="button" value="Inquire" onclick="javascript: submitInquire()" type="button">
<!--Then comes a number of other inputs-->
<input.../>
<input.../>
<input.../>
<input name="modify" class="button" type="button" value="Save"
onclick="javascript: submitModify()" disabled>
</form>
This is some sample code as it's work stuff which I am not allowed to share. So when I use the inquire action a new account successfully loads up and the details are presented on the page. The modify action is meant to 'modify' those details but it just returns the same details displayed on the page. I get no sort of feedback from anything.
You can POST to a URL with a query string (the stuff after the ?), and since you say you're using urllib2 with a data argument, that's what happens. The server can then read both the POST data and the query string and do whatever it wants, though most of the time they're merged together or the query string is ignored entirely.
disabled only stops you from clicking the button in the browser (and even then, you can just un-disable it with a tool like Firebug). You can POST whatever you want to any URL you want; HTML can't stop you, though the server can still give you an error if it wants.
I think your problem is that "inquire" is the default action, and something's wrong with your POST. So no matter what you send, the server isn't recognizing it and is falling back to "inquire".
It looks like the form is intended to send modify=Save. Can you post the Python code you're actually running?
No, what you actually typed in is a GET method.
There are 2 ways of submitting data: POST AND GET.
Post is by submitting data by using a form in a webpage that posts to another on the background, while GET is setting the data in the url itself like user=myuser.
Most of the times using a GET method (url query string) will not work if the web programmer actually is checking for a POST method. The same happens if the programmer is waiting for a GET request and you actually POST it.
However there is a php var called REQUEST which will work with GET and POST.
I'm no professional in PHP but because you had no answers at the moment I tried my best to explain it. Hopefully some expert will come along and explain it properly.
You edited your question while I was replying so you need someone to answer you on your second question.

Tricky ruby on rails problem. Does an easy solution exist?

I hope my question is understandable, else I'm glad to clarify.
We have this sport event coming up, and I have the pleasure to register the people. :)
Facts:
one can have a team of 5-10 persons.
Need to know the order in which the people start.
Need to know who the team leader is.
I did a form in the following style:
o [____Write first name here___] <--- this is a textfield
o [____Write second name here__]
o [___________ ... ____________]
...
the "o" is a radio-button, used to pick the team leader.
I have a model Person and a model Team. Every team has a leader_id (which is one of the Person IDs). Furthermore every team :has_many persons.
In the controller I have
def create
#team = Team.new(params[:team])
#team.save #just assume there are no errors
end
In the view I have (for the radio-buttons):
<input id="team_leader_id_**????**"
name="team[leader_id]"
type="radio"
value="**????**"
/>
<input id="team_leader_id_**????**"
name="team[leader_id]"
type="radio"
value="**????**"
/>
# etc.
My question: What should I put at **????** ?
I don't know the IDs of the persons yet, as they haven't been created. I have to put some meta-ID there, which ruby on rails recognizes and links everything correctly?
You don't have to read the rest (it describes the hack I'm using)
As said, at the moment I'm doing an ugly hack: first save the Team (without generating a leader), then fetch the same team from the db, get its people, and find the first person matching the value of
params[:team][:leader_id].
Finally saving this person's ID in the field of leader_id of the team.
But this code is inefficient, huge and buggy, that I suspect there is an easier way.
The radios should have the same name i.e.
<input id="team_persons_attributes_0_leader_id"
name="team[persons_attributes][leader_id]"
type="radio"
value="0"
/>
<input id="team_persons_attributes_1_leader_id"
name="team[persons_attributes][leader_id]"
type="radio"
value="1"
/>
<input id="team_persons_attributes_2_leader_id"
name="team[persons_attributes][leader_id]"
type="radio"
value="2"
/>
This way there can only be one selected (via the browsers internal radio button mechanism) and params[:team][:persons_attributes][:leader_id] will contain an index to params[:team][:persons] which will be the leader's name.
to obtain the id
team = Team.create(params[:team])
params[:team][:persons].each_with_index{|name, idx|
person = Persons.create(:name => name)
#assuming no errors
team.leader_id = person.id if params[:team][:persons_attributes][:leader_id] == idx
}
It seems as though you are submitting a number of users in one go with one of them flagged as the team leader. In this case you could construct something like:
<%= radio_button_tag "[team][leader]","[1]" %>
<%= radio_button_tag "[team][leader]","[2]" %>>
Then in the controller create the people (using nested attributes?), then simply look up the ID of the one flagged as the leader for the team record.

Resources