gpt4 book ai didi

ruby-on-rails - Ruby on Rails 如何构建支付模型来处理 Paypal REST SDK

转载 作者:太空宇宙 更新时间:2023-11-03 16:23:41 26 4
gpt4 key购买 nike

我想根据官方 Paypal Example on Github 创建一个支付模型.但我一直在创建具有所需字段的模型。

Payment.new({
:intent => "sale",
:payer => {
:payment_method => "paypal" },
:redirect_urls => {
:return_url => "http://localhost:3000/payment/execute",
:cancel_url => "http://localhost:3000/" },
:transactions => [{
:item_list => {
:items => [{
:name => "item",
:sku => "item",
:price => "5",
:currency => "USD",
:quantity => 1 }]},
:amount => {
:total => "5",
:currency => "USD" },
:description => "This is the payment transaction description." }]})

rails g model Payment intent:string 开始......我不知道如何创建像

这样的嵌套字段
:redirect_urls => {
:return_url => "http://localhost:3000/payment/execute",
:cancel_url => "http://localhost:3000/" }

更深入

:transactions =>  [{
:item_list => {
:items => [{
:name => "item",
:sku => "item",
:price => "5",
:currency => "USD",
:quantity => 1 }]},

感谢您的帮助!

最佳答案

您可以使用 OpenStruct为你做这件事。它将是这样的:

paypal_hash = {
:intent => "sale",
:payer => {
:payment_method => "paypal" },
:redirect_urls => {
:return_url => "http://localhost:3000/payment/execute",
:cancel_url => "http://localhost:3000/" },
:transactions => [{
:item_list => {
:items => [{
:name => "item",
:sku => "item",
:price => "5",
:currency => "USD",
:quantity => 1 }]},
:amount => {
:total => "5",
:currency => "USD" },
:description => "This is the payment transaction description." }]}

paypal_obj = OpenStruct.new(paypal_hash)
paypal_obj.intent
# => "sales"

关于ruby-on-rails - Ruby on Rails 如何构建支付模型来处理 Paypal REST SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42640342/

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