Ruby on rails Paypal自适应支付Rails中的自动流程

Ruby on rails Paypal自适应支付Rails中的自动流程,ruby-on-rails,paypal,ruby-on-rails-4,paypal-adaptive-payments,Ruby On Rails,Paypal,Ruby On Rails 4,Paypal Adaptive Payments,我正在将Paypal集成到我的Rails web应用程序中。我需要实施下一个用例: 客户购买服务并向我的应用付费 几天后,例如,一周后,我向服务提供商支付了一笔费用。 第二点,我有一个引擎,它自动检查客户的付款日期是否已经到了。如果是这样,它会尝试自动向提供商付款 我有我的第1点,实施并使用Express Checkout。 对于我的第2点,我理解我应该使用适应性支付API。但是,据我所知,它不起作用,所以我不确定 我的第一个问题是,我希望一切都是自动化的,所以,我不希望任何窗口弹出来确认任何事

我正在将Paypal集成到我的Rails web应用程序中。我需要实施下一个用例:

  • 客户购买服务并向我的应用付费
  • 几天后,例如,一周后,我向服务提供商支付了一笔费用。 第二点,我有一个引擎,它自动检查客户的付款日期是否已经到了。如果是这样,它会尝试自动向提供商付款 我有我的第1点,实施并使用Express Checkout。 对于我的第2点,我理解我应该使用适应性支付API。但是,据我所知,它不起作用,所以我不确定

    我的第一个问题是,我希望一切都是自动化的,所以,我不希望任何窗口弹出来确认任何事情?是否可以自动执行该操作

    我的代码:

    def pay(amount, paypalAccountEmail)
    
      # ## Build request object
      @pay_request = @api.build_pay()
    
      # The action for this request. Possible values are:
      # 
      # * PAY - Use this option if you are not using the Pay request in
      # combination with ExecutePayment.
      # * CREATE - Use this option to set up the payment instructions with
      # SetPaymentOptions and then execute the payment at a later time with
      # the ExecutePayment.
      # * PAY_PRIMARY - For chained payments only, specify this value to delay
      # payments to the secondary receivers; only the payment to the primary
      # receiver is processed.
      @pay_request.actionType         = "PAY"
    
      # URL to redirect the sender's browser to after
      # canceling the approval for a payment; it is always required but only
      # used for payments that require approval (explicit payments)
      @pay_request.cancelUrl          = "https://paypal-sdk-samples.herokuapp.com/adaptive_payments/pay"
    
      # The code for the currency in which the payment is
      # made; you can specify only one currency, regardless of the number of
      # receivers
      @pay_request.currencyCode       = "EUR"
    
      # The payer of PayPal fees. Allowable values are:
      # 
      # * SENDER - Sender pays all fees (for personal, implicit simple/parallel payments; do not use for chained or unilateral payments)
      # * PRIMARYRECEIVER - Primary receiver pays all fees (chained payments only)
      # * EACHRECEIVER - Each receiver pays their own fee (default, personal and unilateral payments)
      # * SECONDARYONLY - Secondary receivers pay all fees (use only for chained payments with one secondary receiver)
      @pay_request.feesPayer          = "SENDER"
    
      # The URL to which you want all IPN messages for this payment to be sent.
      @pay_request.ipnNotificationUrl = "https://paypal-sdk-samples.herokuapp.com/adaptive_payments/ipn_notify"
    
      # Amount to be paid to the receiver.
      @pay_request.receiverList.receiver[0].amount = amount
    
      # Receiver's email address. This address can be unregistered with paypal.com. If so, a receiver cannot claim the payment until a PayPal account is linked to the email address. The PayRequest must pass either an email address or a phone number.
      @pay_request.receiverList.receiver[0].email  = paypalAccountEmail
    
      # The URL to which the sender's browser is redirected after approving a payment on paypal.com. Specify the URL with the HTTP or HTTPS designator.
      @pay_request.returnUrl          = "https://paypal-sdk-samples.herokuapp.com/adaptive_payments/pay"
    
      # ## Make API call & get response
      @pay_response = @api.pay(@pay_request)
    
      # ## Access Response
      # ### Success Response
    
      if @pay_response.responseEnvelope.ack == "Success"
        # Once you get success response, user has to redirect to PayPal
        # for the payment. Construct redirectURL as follows,
        # `redirectURL=https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey="
        # + @pay_response.payKey;`
    
        # The pay key, which is a token you use in other Adaptive
        # Payment APIs (such as the Refund Method) to identify this
        # payment. The pay key is valid for 3 hours; the payment must
        # be approved while the pay key is valid.
        puts  @pay_response.payKey
    
        # The status of the payment. Possible values are:
        # 
        # * CREATED - The payment request was received; funds will be transferred once the payment is approved
        # * COMPLETED - The payment was successful
        # * INCOMPLETE - Some transfers succeeded and some failed for a parallel payment or, for a delayed chained payment, secondary receivers have not been paid
        # * ERROR - The payment failed and all attempted transfers failed or all completed transfers were successfully reversed
        # * REVERSALERROR - One or more transfers failed when attempting to reverse a payment
        # * PROCESSING - The payment is in progress
        # * PENDING - The payment is awaiting processing
        puts "Pay Key : " + @pay_response.paymentExecStatus
    
        # ###Error Response
      else
        puts @pay_response.error[0].message
    
      end
      @pay_response
    end
    
    和我的日志:

    providerPayment-->begin
    Request[post]: https://svcs.sandbox.paypal.com/AdaptivePayments/Pay
    Response[200]: OK, Duration: 1.417s
    AP-1E607027P7722991V
    Pay Key : CREATED
    providerPayment-->ok
    

    我从Paypal上取了一个例子,但当我执行它时,我看到结果是好的。我的actionType=“支付”。所以,我想付款,但在密钥中,我得到了=创建,之后什么也没有发生。我不想创建,但想完成事务。我遗漏了什么?

    我看不到您正在将用户重定向到任何地方。。??在您拨打支付电话后,您必须将用户重定向到PayPal以登录并验证支付。唯一一次你不会这样做的是,如果你在薪资申请中包含预批准密钥,但我看不出你是这样做的

    您需要将获得的paykey附加到重定向到的PayPal URL的末尾。以下是一个示例:

    在用户登录并完成该支付密钥的支付之前,它实际上只是被创建的

    实际上,我在代码的注释中看到了一些关于重定向URL的信息,但我没有看到任何实际执行重定向以将用户发送到那里的信息

    -----更新-----

    现在我看到您正在进行隐式支付,您只需要确保在请求中包含senderEmail。这是我刚刚提出的一个支付请求的示例,它使用隐式批准,因此重定向和进一步的身份验证是不必要的

    <?xml version="1.0" encoding="utf-8"?>
    <PayRequest xmlns="http://svcs.paypal.com/types/ap">
      <requestEnvelope xmlns="">
        <detailLevel>ReturnAll</detailLevel>
        <errorLanguage>en_US</errorLanguage>
      </requestEnvelope>
      <actionType xmlns="">PAY</actionType>
      <cancelUrl xmlns="">http://paypal.angelleye.com/paypal/class/1.2/Pay_Cancel.php</cancelUrl>
      <clientDetails xmlns="">
        <applicationId xmlns="">APP-80W284485P519543T</applicationId>
        <ipAddress xmlns="">192.168.1.115</ipAddress>
        <partnerName xmlns="">Always Give Back</partnerName>
      </clientDetails>
      <currencyCode xmlns="">USD</currencyCode>
      <receiverList xmlns="">
        <receiver xmlns="">
          <amount xmlns="">10.00</amount>
          <email xmlns="">sandbo_1204199080_biz@angelleye.com</email>
        </receiver>
        <receiver xmlns="">
          <amount xmlns="">5.00</amount>
          <email xmlns="">usb_1329725429_biz@angelleye.com</email>
        </receiver>
      </receiverList>
      <sender>
        <useCredentials xmlns=""></useCredentials>
      </sender>
      <account xmlns="">
        <phone xmlns=""></phone>
      </account>
      <returnUrl xmlns="">http://paypal.angelleye.com/paypal/class/1.2/Pay_Return.php</returnUrl>
      <senderEmail xmlns="">sandbo_1215254764_biz@angelleye.com</senderEmail>
    </PayRequest>
    
    
    返回所有
    恩努斯
    支付
    http://paypal.angelleye.com/paypal/class/1.2/Pay_Cancel.php
    APP-80W284485P519543T
    192.168.1.115
    永远回馈
    美元
    10
    sandbo_1204199080_biz@angelleye.com
    5
    USB1329725429_biz@angelleye.com
    http://paypal.angelleye.com/paypal/class/1.2/Pay_Return.php
    sandbo_1215254764_biz@angelleye.com
    
    下面是响应,它显示paymentExecStatus已完全完成,而不是像未经隐式批准那样刚刚创建/挂起

    <?xml version='1.0' encoding='UTF-8'?>
    <ns2:PayResponse xmlns:ns2="http://svcs.paypal.com/types/ap">
      <responseEnvelope>
        <timestamp>2014-01-20T07:53:08.420-08:00</timestamp>
        <ack>Success</ack>
        <correlationId>c74cd2a669678</correlationId>
        <build>7935900</build>
      </responseEnvelope>
      <payKey>AP-39D64611TH198910V</payKey>
      <paymentExecStatus>COMPLETED</paymentExecStatus>
      <paymentInfoList>
        <paymentInfo>
          <transactionId>0M064165EV3552504</transactionId>
          <transactionStatus>COMPLETED</transactionStatus>
          <receiver>
            <amount>10.00</amount>
            <email>sandbo_1204199080_biz@angelleye.com</email>
            <primary>false</primary>
            <accountId>E7BTGVXBFSUAU</accountId>
          </receiver>
          <pendingRefund>false</pendingRefund>
          <senderTransactionId>43F26555RA073153C</senderTransactionId>
          <senderTransactionStatus>COMPLETED</senderTransactionStatus>
        </paymentInfo>
        <paymentInfo>
          <transactionId>7K9309808X980452U</transactionId>
          <transactionStatus>COMPLETED</transactionStatus>
          <receiver>
            <amount>5.00</amount>
            <email>usb_1329725429_biz@angelleye.com</email>
            <primary>false</primary>
            <accountId>C9TAVNJFATXCS</accountId>
          </receiver>
          <pendingRefund>false</pendingRefund>
          <senderTransactionId>0M822840XM282203C</senderTransactionId>
          <senderTransactionStatus>COMPLETED</senderTransactionStatus>
        </paymentInfo>
      </paymentInfoList>
      <sender>
        <accountId>ATSCG2QMC9KAU</accountId>
      </sender>
    </ns2:PayResponse>
    
    
    2014-01-20T07:53:08.420-08:00
    成功
    c74cd2a669678
    7935900
    AP-39D64611TH198910V
    完整的
    0M064165EV3552504
    完整的
    10
    sandbo_1204199080_biz@angelleye.com
    假的
    E7BTGVBFSUAU
    假的
    43F26555RA073153C
    完整的
    7K9309808X980452U
    完整的
    5
    USB1329725429_biz@angelleye.com
    假的
    C9TAVNJFATXCS
    假的
    0M822840XM282203C
    完整的
    ATSCG2QMC9KAU
    

    因此,无论您使用什么类库,都应该能够轻松添加额外的senderEmail参数,这将解决您的问题。

    我看不到您在任何地方重定向用户。。??在您拨打支付电话后,您必须将用户重定向到PayPal以登录并验证支付。唯一一次你不会这样做的是,如果你在薪资申请中包含预批准密钥,但我看不出你是这样做的

    您需要将获得的paykey附加到重定向到的PayPal URL的末尾。以下是一个示例:

    在用户登录并完成该支付密钥的支付之前,它实际上只是被创建的

    实际上,我在代码的注释中看到了一些关于重定向URL的信息,但我没有看到任何实际执行重定向以将用户发送到那里的信息

    -----更新-----

    现在我看到您正在进行隐式支付,您只需要确保在请求中包含senderEmail。这是我刚刚提出的一个支付请求的示例,它使用隐式批准,因此重定向和进一步的身份验证是不必要的

    <?xml version="1.0" encoding="utf-8"?>
    <PayRequest xmlns="http://svcs.paypal.com/types/ap">
      <requestEnvelope xmlns="">
        <detailLevel>ReturnAll</detailLevel>
        <errorLanguage>en_US</errorLanguage>
      </requestEnvelope>
      <actionType xmlns="">PAY</actionType>
      <cancelUrl xmlns="">http://paypal.angelleye.com/paypal/class/1.2/Pay_Cancel.php</cancelUrl>
      <clientDetails xmlns="">
        <applicationId xmlns="">APP-80W284485P519543T</applicationId>
        <ipAddress xmlns="">192.168.1.115</ipAddress>
        <partnerName xmlns="">Always Give Back</partnerName>
      </clientDetails>
      <currencyCode xmlns="">USD</currencyCode>
      <receiverList xmlns="">
        <receiver xmlns="">
          <amount xmlns="">10.00</amount>
          <email xmlns="">sandbo_1204199080_biz@angelleye.com</email>
        </receiver>
        <receiver xmlns="">
          <amount xmlns="">5.00</amount>
          <email xmlns="">usb_1329725429_biz@angelleye.com</email>
        </receiver>
      </receiverList>
      <sender>
        <useCredentials xmlns=""></useCredentials>
      </sender>
      <account xmlns="">
        <phone xmlns=""></phone>
      </account>
      <returnUrl xmlns="">http://paypal.angelleye.com/paypal/class/1.2/Pay_Return.php</returnUrl>
      <senderEmail xmlns="">sandbo_1215254764_biz@angelleye.com</senderEmail>
    </PayRequest>
    
    
    返回所有
    恩努斯
    支付
    http://paypal.angelleye.com/paypal/class/1.2/Pay_Cancel.php
    APP-80W284485P519543T
    192.168.1.115
    永远回馈
    美元
    10
    sandbo_1204199080_biz@angelleye.com
    5
    USB1329725429_biz@angelleye.com
    http://paypal.angelleye.com/paypal/class/1.2/Pay_Return.php
    sandbo_1215254764_biz@angelleye.com
    
    下面是响应,它显示paymentExecStatus已完全完成,而不是像未经隐式批准那样刚刚创建/挂起

    <?xml version='1.0' encoding='UTF-8'?>
    <ns2:PayResponse xmlns:ns2="http://svcs.paypal.com/types/ap">
      <responseEnvelope>
        <timestamp>2014-01-20T07:53:08.420-08:00</timestamp>
        <ack>Success</ack>
        <correlationId>c74cd2a669678</correlationId>
        <build>7935900</build>
      </responseEnvelope>
      <payKey>AP-39D64611TH198910V</payKey>
      <paymentExecStatus>COMPLETED</paymentExecStatus>
      <paymentInfoList>
        <paymentInfo>
          <transactionId>0M064165EV3552504</transactionId>
          <transactionStatus>COMPLETED</transactionStatus>
          <receiver>
            <amount>10.00</amount>
            <email>sandbo_1204199080_biz@angelleye.com</email>
            <primary>false</primary>
            <accountId>E7BTGVXBFSUAU</accountId>
          </receiver>
          <pendingRefund>false</pendingRefund>
          <senderTransactionId>43F26555RA073153C</senderTransactionId>
          <senderTransactionStatus>COMPLETED</senderTransactionStatus>
        </paymentInfo>
        <paymentInfo>
          <transactionId>7K9309808X980452U</transactionId>
          <transactionStatus>COMPLETED</transactionStatus>
          <receiver>
            <amount>5.00</amount>
            <email>usb_1329725429_biz@angelleye.com</email>
            <primary>false</primary>
            <accountId>C9TAVNJFATXCS</accountId>
          </receiver>
          <pendingRefund>false</pendingRefund>
          <senderTransactionId>0M822840XM282203C</senderTransactionId>
          <senderTransactionStatus>COMPLETED</senderTransactionStatus>
        </paymentInfo>
      </paymentInfoList>
      <sender>
        <accountId>ATSCG2QMC9KAU</accountId>
      </sender>
    </ns2:PayResponse>
    
    
    2014-01-20T07:53:08.420-08:00
    成功
    c74cd2a669678
    7935900
    AP-39D64611TH198910V
    完整的
    0M064165EV3552504
    完整的
    10
    sandbo_1204199080_biz@angelleye.com
    假的
    E7BTGVBFSUAU
    假的
    43F26555RA073153C
    完整的
    7K9309808X980452U
    完整的
    5
    USB1329725429_biz@angelleye.com
    假的
    C9TAVNJFATXCS
    假的
    0M822840XM282203C
    完整的
    ATSCG2QMC9KAU
    

    因此,无论您使用什么类库,都应该能够轻松添加额外的senderEmail参数,这将解决您的问题。

    我看不到您在任何地方重定向用户。。??在您拨打支付电话后,您必须将用户重定向到PayPal以登录并验证支付。这个