亚马逊Flex支付AmazonFlexPay.Pay?

时间:2013-06-26 18:12:16

标签: rubygems amazon amazon-fps

好的,我正在使用SelfStarter,我已经设置了一个FlexPay帐户,并输入SelfStarter使其工作所需的信息,secret_key,access_key。

之前从未使用过FlexPay。

现在,经过测试(作为支持者),我可以下订单,结账,然后我收到一封电子邮件,说我已经授权付款。但是,没有钱转手。

经过进一步研究,我发现我需要使用AmazonFlexPay.Pay根据收集的令牌向帐户收费。这很酷,但我找不到有关如何实际实现此代码的大量信息,例如它与其余代码相关的位置。这是我能找到的大部分信息。

AmazonFlexPay.pay('12.99', 'USD', 'STOKEN', 'myrequest3292')

这是SelfStarter控制器的代码,

class PreorderController < ApplicationController
  skip_before_filter :verify_authenticity_token, :only => :ipn

  def index
  end

  def checkout
  end

  def prefill
    @user  = User.find_or_create_by_email!(params[:email])

    if Settings.use_payment_options
      payment_option_id = params['payment_option']
      raise Exception.new("No payment option was selected") if payment_option_id.nil?
      payment_option = PaymentOption.find(payment_option_id)
      price = payment_option.amount
    else
      price = Settings.price
    end

    @order = Order.prefill!(:name => Settings.product_name, :price => price, :user_id => @user.id, :payment_option => payment_option)

    # This is where all the magic happens. We create a multi-use token with Amazon, letting us charge the user's Amazon account
    # Then, if they confirm the payment, Amazon POSTs us their shipping details and phone number
    # From there, we save it, and voila, we got ourselves a preorder!
    port = Rails.env.production? ? "" : ":3000"
    callback_url = "#{request.scheme}://#{request.host}#{port}/preorder/postfill"
    redirect_to AmazonFlexPay.multi_use_pipeline(@order.uuid, callback_url,
                                                 :transaction_amount => price,
                                                 :global_amount_limit => price + Settings.charge_limit,
                                                 :collect_shipping_address => "True",
                                                 :payment_reason => Settings.payment_description)
  end

  def postfill
    unless params[:callerReference].blank?
      @order = Order.postfill!(params)
    end
    # "A" means the user cancelled the preorder before clicking "Confirm" on Amazon Payments.
    if params['status'] != 'A' && @order.present?
      redirect_to :action => :share, :uuid => @order.uuid
    else
      redirect_to root_url
    end
  end

  def share
    @order = Order.find_by_uuid(params[:uuid])
  end

  def ipn
  end
end

此外红宝石到目前为止仍未受到影响,因此您可能需要查看其他任何内容,https://github.com/lockitron/selfstarter

SelfStarter一直坚持,因为它似乎已准备好退出包装。情况似乎并非如此,所以任何帮助都将受到赞赏。我觉得我可能会忽略一个简单的步骤。

0 个答案:

没有答案