我想用貝寶快遞寶石來實現貝寶快遞付款。然而,我很困惑。貝寶快車寶石Rails整合
這裏是在交易控制器創建方法
elsif params[:purchase][:payment_method] == "Paypal"
#paypal payment
request = Paypal::Express::Request.new(
:username => "xxxxxxxxxxxxxxxxx",
:password => "xxxxxxxxxxxxxxxx",
:signature => "xxxxxxxxxxxxxxxx"
)
payment_request = Paypal::Payment::Request.new(
:currency_code => "#{@current_user.currency}", # if nil, PayPal use USD as default
:description => "Purchase of SMS", # item description
:quantity => 1, # item quantity
:amount => "#{@total}", # item value
)
response = request.setup(
payment_request,
success_url,
cancel_url
)
transaction.tracking_id = response.token
transaction.save
response.redirect_uri
而且成功方法
def success
token = params[:token]
payer_id = params[:payer_id]
request = Paypal::Express::Request.new(
:username => "xxxxxxxxxxxxxxx",
:password => "xxxxxxxxxxxxxxx",
:signature => "xxxxxxxxxxxxxxx"
)
response = request.details(token)
transaction = Transaction.find_by_tracking_id(token)
transaction.merchant_reference = payer_id
transaction.status = "Completed"
transaction.save
user = User.find(transaction.user_id)
user.balance = (user.balance+response.amount.to_i)
user.save()
response = request.checkout!(
token,
payer_id,
payment_request
)
flash[:notice] = 'Payment Transaction Completed'
user_home_path(@current_user)
end
和取消方法
def cancel
flash[:warn] = 'Payment Request Canceled'
user_home_path(@current_user)
end
代碼我怎樣才能使一個適當的請求在create方法中,獲取一個令牌作爲響應並存儲它以便能夠在s中使用它訪問方法來搜索特定的交易。
另外,我怎樣才能在成功的方法中執行正確DoExpressCheckoutPayment
。
預先感謝您。
該行只是一場賭博..只是複製了我的困惑狀態的代碼。 – acacia
@acacia是否能夠獲得此寶石的工作? – pwz2000
@ pwz2000,我很久以前就開始工作了..我剛剛使用NVP classic API很久以前 – acacia