1

好的,所以我正在使用 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,因为它似乎已经准备好从包装中取出。情况似乎并非如此,因此将不胜感激。我觉得我可能忽略了一个简单的步骤或其他东西。

4

0 回答 0