현재 PayPal의 Express Checkout 및 ActiveMerchant를 통해 PayPal 결제를 허용하는 Ruby-on-Rails 웹 응용 프로그램을 작성 중입니다. 나는 고객/구매자가 검증 된 또는 확인되지 않은 PayPal 계정 중 하나를 사용하여 지불했는지 여부를 판단하기위한 ActiveMerchant의 지원에 대한 여러 조사를 수행했지만 유용한 가이드를 찾는 데는 운이 없다.PayPal Express Checkout 고객/구매자의 계정 상태 (확인 됨/확인되지 않음)를 확인하는 ActiveMerchant의 지원
ActiveMerchant는 현재 잘 문서화되어 있지 않으므로 전혀 도움이되지 않습니다.
다음은 현재 내 프로젝트에서 사용중인 관련 코드입니다. PaymentsController # purchase에서 EXPRESS_GATEWAY.purchase 메소드 호출에 의해 반환 된 ActiveMerchant::Billing::PaypalExpressResponse
객체의 #params['protection_eligibility']
및 #params['protection_eligibility_type']
메소드를 일시적으로 사용하여 PayPal 고객/구매자가 확인 된/확인되지 않은 PayPal 계정이 있는지 평가합니다. 나중에 이것이 고객의 계정 상태를 알기위한 신뢰할 수있는 근거가 아니라는 사실을 알게되었습니다.
Ruby-on-Rails의 ActiveMerchant를 사용하거나 Rails의 다른 대안을 사용하여 PayPal 고객/구매자가 확인/확인되지 않은 계정을 가지고 있는지 여부를 아는 사람이 나에게 지혜를 줄 수 있기를 바랍니다.
# config/environments/development.rb
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
paypal_options = {
# credentials removed for this StackOverflow question
:login => "",
:password => "",
:signature => ""
}
::EXPRESS_GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
end
# app/models/payment.rb
class Payment < ActiveRecord::Base
# ...
PAYPAL_CREDIT_TO_PRICE = {
# prices in cents(US)
1 => 75_00,
4 => 200_00,
12 => 550_00
}
STATUSES = ["pending", "complete", "failed"]
TYPES = ["paypal", "paypal-verified", "paypal-unverified", "wiretransfer", "creditcard"]
# ...
end
# app/controllers/payments_controller.rb
class PaymentsController < ApplicationController
# ...
def checkout
session[:credits_qty] = params[:credit_qty].to_i
total_as_cents = Payment::PAYPAL_CREDIT_TO_PRICE[session[:credits_qty]]
setup_purchase_params = {
:allow_guest_checkout => true,
:ip => request.remote_ip,
:return_url => url_for(:action => 'purchase', :only_path => false),
:cancel_return_url => url_for(:controller => 'payments', :action => 'new', :only_path => false),
:items => [{
:name => pluralize(session[:credits_qty], "Credit"),
:number => 1,
:quantity => 1,
:amount => Payment::PAYPAL_CREDIT_TO_PRICE[session[:credits_qty]]
}]
}
setup_response = EXPRESS_GATEWAY.setup_purchase(total_as_cents, setup_purchase_params)
redirect_to EXPRESS_GATEWAY.redirect_url_for(setup_response.token)
end
def purchase
if params[:token].nil? or params[:PayerID].nil?
redirect_to new_payment_url, :notice => I18n.t('flash.payment.paypal.error')
return
end
total_as_cents = Payment::PAYPAL_CREDIT_TO_PRICE[session[:credits_qty]]
purchase_params = {
:ip => request.remote_ip,
:token => params[:token],
:payer_id => params[:PayerID],
:items => [{
:name => pluralize(session[:credits_qty], "Credit"),
:number => 1,
:quantity => 1,
:amount => Payment::PAYPAL_CREDIT_TO_PRICE[session[:credits_qty]]
}]
}
purchase = EXPRESS_GATEWAY.purchase total_as_cents, purchase_params
if purchase.success?
payment = current_user.payments.new
payment.paypal_params = params
payment.credits = session[:credits_qty]
payment.amount = Payment::PAYPAL_CREDIT_TO_PRICE[session[:credits_qty]]
payment.currency = "USD"
payment.status = "complete"
if(purchase.params["receipt_id"] && (purchase.params["success_page_redirect_requested"] == "true"))
payment.payment_type = "creditcard"
else
if purchase.params['protection_eligibility'] == 'Eligible' && purchase.params['protection_eligibility_type'] == 'ItemNotReceivedEligible,UnauthorizedPaymentEligible'
payment.payment_type = 'paypal-verified'
else
payment.payment_type = 'paypal-unverified'
end
end
payment.ip_address = request.remote_ip.to_s
payment.save!
SiteMailer.paypal_payment(payment).deliver
SiteMailer.notice_payment(payment).deliver
notice = I18n.t('flash.payment.status.thanks')
redirect_to profile_url, :notice => notice
else
notice = I18n.t('flash.payment.status.failed', :message => purchase.message)
redirect_to new_payment_url, :notice => notice
end
end
# ...
end
정확히 무엇 당신 질문입니까? –
Hello Beerlington, 내 질문은, ActiveMerchant는 PayPal Express Checout 지불이 검증 된/확인되지 않은 PayPal 계정에 의해 수행되었음을 나타내는 기능이 있습니까? – ebcagadas