gpt4 book ai didi

ruby-on-rails - PayPal Express Checkout 具有多个项目,并且有活跃的商家在 rails

转载 作者:太空宇宙 更新时间:2023-11-03 15:48:25 24 4
gpt4 key购买 nike

我正在尝试对多个项目使用 PayPal ExpressCheckout 按钮,但没有成功。我正在使用 NetBeans IDE、rails 4 和 MySQL db。这是我到目前为止所做的:

In my production.rb file I have:

Rails.application.configure 做 配置/application.rb.

config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
paypal_options = {
:login => "xxxx",
:password => "xxxx ",
:signature => "xxxx "
}

::STANDARD_GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(paypal_options)
::EXPRESS_GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
end

In my transaction.rb model I have:

def valid_purchase

if express_token.blank?
standard_purchase
else
express_token
end


def express_purchase

# price_in_cents = total
response = EXPRESS_GATEWAY.purchase(total, express_purchase_options)

if response.success?
self.status = "processed"
else
errors.add(:transactions, "---- #{response.message}.")
end
end

def express_token=(token)
self[:express_token] = token
if new_record? && !token.blank?

details = EXPRESS_GATEWAY.details_for(token)
self.express_payer_id = details.payer_id
self.ship_to_first_name = details.params["first_name"]
self.ship_to_last_name = details.params["last_name"]

end
end



private
def express_purchase_options
{
:ip => customer_ip,
:token => express_token,
:payer_id => express_payer_id
}
end

And in my transaction_controller.rb I have:

def express_checkout
order_items =[]
postage_rate=nil
item = Hash.new
@order = Order.find(session[:order_id])
@receipts = Receipt.where(:order_id=>@order.id)
@receipts.each do |r|
postage_rate = r.postage_rate * 100
end

@cart = Cart.find(@order.cart_id)
@cart.cart_items.each do |i|
@product = Product.find(i.product_id)

item = {
name: @product.product_name,
quantity: i.amount,
description: "ORDER_ID: #{@order.id}",
amount: @product.selling_price * 100 ,
shipping: postage_rate/@cart.cart_items.size
}
order_items << item
end
price_in_cents = (@order.total_p_pr * 100).round(2)

options = {
:ip => request.remote_ip,
:return_url => url_for(:action=>:new, :only_path => false),
:cancel_return_url => catalogs_traders_url,
:currency => "USD",
:allow_guest_checkout=> true,
:items => order_items # this line outputs: [{:name=>"owl potty", :quantity=>1, :description=>"ORDER_ID: 249", :amount=>2808.0, :shipping=>332.0}, {:name=>"a bag", :quantity=>1, :description=>"ORDER_ID: 249", :amount=>1260.0, :shipping=>332.0}, {:name=>"bracelet", :quantity=>1, :description=>"ORDER_ID: 249", :amount=>120.0, :shipping=>332.0}, {:name=>"beautiful woman", :quantity=>1, :description=>"ORDER_ID: 249", :amount=>74352.0, :shipping=>332.0}]

}

#passing the cost of the order
response = EXPRESS_GATEWAY.setup_purchase(price_in_cents,options )
redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)
end

def new

@transaction = Transaction.new(:express_token => params[:token])

end

我得到:

enter image description here

我们非常欢迎任何帮助。谢谢!

最佳答案

我非常非常小心地刷了这个帖子

setting tax amount in Active Merchant / PayPal Express Checkout我明白我的错误。这是我更正的 transaction_controller:

# to redirect to PayPay site
def express_checkout
pr = nil
tp = nil
items =[]
postage_r=[]
total_p = []

order_items =[]
postage_rate=nil
item = Hash.new
@order = Order.find(session[:order_id])
@receipts = Receipt.where(:order_id=>@order.id)
@receipts.each do |r|
total_p << r.total_price
postage_r << r.postage_rate

end
tp = total_p.inject{|sum,x| sum + x }
pr = postage_r.inject{|sum,x| sum + x }
@cart = Cart.find(@order.cart_id)
@cart.cart_items.each do |i|
@product = Product.find(i.product_id)

item = {
name: @product.product_name,
quantity: i.amount,
description: "ORDER_ID: #{@order.id}",
amount: @product.selling_price * 100 ,

}
order_items << item
end


price_in_cents = (@order.total_p_pr * 100).round(2)

options = {
:subtotal => tp * 100,
:shipping => pr * 100,
:handling => 0,
:tax => 0,
:ip => request.remote_ip,
:return_url => url_for(:action=>:new, :only_path => false),
:cancel_return_url => catalogs_traders_url,
:currency => "USD",
:allow_guest_checkout=> true,
:items => order_items
}

#passing the cost of the order
response = EXPRESS_GATEWAY.setup_purchase(price_in_cents,options )

redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)
end

成功了。我希望我的帖子对想要集成 Express Checkout 按钮的人有用。谢谢你的帮助!

关于ruby-on-rails - PayPal Express Checkout 具有多个项目,并且有活跃的商家在 rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33317465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com