require 'active_merchant'
ActiveMerchant::Billing::Base.mode = :test
paypal_options = {
login: "activemerchant-test_api1.example.com",
password: "HBC6A84QLRWC923A",
signature: "AFcWxV21C7fd0v3bYYYRCpSSRl31AC-11AKBL8FFO9tjImL311y8a0hx"
}
@gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
response = @gateway.setup_purchase(50,
ip: request.remote_ip,
return_url: "http://local.mywebdomain.com:3000/mylocalhostpaymentsucceed",
cancel_return_url: "http://local.mywebdomain.com:3000/seeyouagain",
currency: "USD",
allow_guest_checkout: true,
items: [{name: "Order", description: "Order description", quantity: "1", amount: 50}]
)
redirect_to @gateway.redirect_url_for(response.token)
另一个技巧是如何将 localhost 设置为 local.mywebdomain.com。只需将您机器的 system32 文件夹中的 .host 文件编辑为
127.0.0.1 local.mywebdomain.com