ho fatto una semplice applicazione per dimostrare come off-site pagamenti per Worldpay e Rails/Activemerchant possono lavorare insieme.
Demo Rails App - https://github.com/daemonsy/Worldpay-Rails--Off-Site--Integration-Example
per World Pay ospitato il pagamento, in pratica un post
al loro URL è richiesto il pagamento. Aggiungi test-
a secure.worldpay.com per la modalità di test. WP richiede importo, valuta, ID di installazione e cartId per rendere la pagina al cliente.
<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 ">
Fonte: http://www.worldpay.com/support/kb/bg/htmlredirect/rhtml.html
Questo crea una semplice button
che porta il tuo ordine a World Pay in cui il cliente inserire i dati della carta di credito e completare l'acquisto. Ho incorporato il codice sopra nella pagina show
di un controller degli ordini. e, g, <input type="hidden" name="amount" value="<%[email protected]"%>>
. Quindi puoi fare clic su buy this
dopo aver inviato l'ordine. Esistono molti modi per ottenere uno POST
su World Pay.
Dopodiché, World Pay può mostrare una pagina di risposta dell'acquirente, inviarti payment response
ecc. Per la risposta di pagamento al lavoro, è possibile impostare la risposta di pagamento callback URL
a uno dei controller. per esempio. =>http://mysite.com/payment-backend
Questa sarà una richiesta POST
quindi è necessario configurare il controller per gestirlo. Questo è dove Activemerchant
calci. Ad esempio,
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
Così l'oggetto di notifica leggerà il params in request.raw_post
e impostare l'un oggetto in cui è possibile interrogare. Ho trovato utili i documenti del commerciante attivo nel dire quali parametri di ritorno sono mappati da esso.
Si noti che questo controller è un esempio molto grezzo. World Pay fornisce alcuni metodi per convalidare la risposta e questo è supportato da Active Merchant.
ActiveMerchant Docs su WorldPay :: Comunicazioni http://rdoc.info/github/Shopify/active_merchant/master/ActiveMerchant/Billing/Integrations/WorldPay Documenti World Pay Response pagamento http://www.worldpay.com/support/kb/bg/paymentresponse/payment_response.html
siete riusciti a risolvere questo problema? Sto anche avendo problemi a cambiare :( –
No. Non ho ancora trovato nulla – Mike
Dato che stai usando il pagamento fuori sede, potresti semplificare il processo facendo il 'POST' su un URL worldpay? Come l'API del pulsante Paypal. –