我正在尝试在我的电子商务应用程序中实现PaypalExpressCheckout,该应用程序是基于Rails3构建的。
应用程序中将有两个角色 - 卖方和买方
我在这里面临的问题是,当买家退房时,金额已成功转入卖家帐户,但未从买家帐户中扣除相同金额。
我从Paypal沙箱配置了API凭据,以下是我在ActiveMerchant gem中使用的方法:
来自控制器:
def checkout
values = {:ip => request.remote_ip,
:return_url => confirm_paypal_url(@payment),
:cancel_return_url => root_url, :shipping => 0,
:handling => 0, :tax => 0,
:items => get_items(session[:cart])}
response = @payment.setup_purchase(values)
redirect_to @payment.redirect_url_for(response.token)
end
## CALL BACK
def paypal
# session[:product_users] = [{:amount => '100', :email => 'xx@x.com'}]
session[:product_users].each do |user|
@payment = if user.last.nil?
@payment.purchase(:token => params[:token], :payer_id => params[:PayerID], :ip => request.remote_ip)
else
@payment.transfer(user[:amount], user[:email])
end
@payment.save
end
redirect_to billing_thank_you_url(@payment)
end
来自模特:
def setup_purchase(options)
gateway.setup_purchase(amount * 100, options)
end
def transfer(amount, receiver)
response = gateway.transfer(amount * 100, receiver, :subject => "Payment from XXX")
end
如果有人帮助我,我将不胜感激。
谢谢