gpt4 book ai didi

ruby-on-rails - 我收到了 Paypal IPN 罚款,但我的应用程序仅在从 paypal 帐户完成时才记录它。由 UTF-8/ISO-8859-1 引起

转载 作者:太空宇宙 更新时间:2023-11-03 16:03:59 26 4
gpt4 key购买 nike

这是在 Ruby On Rails 3 测试环境中完成的,这是一个与生产环境相同的 MySQL 的 phusion 乘客。我使用了本教程:http://railscasts.com/episodes/142-paypal-notifications?autoplay=true从 paypal 获得 IPN 以通知我的应用程序付款结束。

我工作得很好,当我的测试设置完成结帐时,我可以在 Paypal 上看到我的购物车的内容,我登录到 paypal 沙盒帐户,paypal 通知我,我在我的数据库中创建了一个通知条目。

但是,如果我决定不使用 paypal 帐户而是使用支付卡进行支付,它会莫名其妙地失败。在日志上有来自 paypal 的答案,但我的应用程序从未创建 INSERT :

以下是 Paypal 用户通知的日志:

Started POST "/notification_paiements?secret=testsecret" for 173.0.82.126 at 2011-11-09 18:25:18 +0100
Processing by NotificationPaiementsController#create as HTML
Parameters: {"mc_gross"=>"287.04", "invoice"=>"36", "protection_eligibility"=>"Ineligible", "address_status"=>"unconfirmed", "item_number1"=>"1", "payer_id"=>"N9JJ8RH7BM8EU", "tax"=>"47.04", "address_street"=>"Av. de la Pelouse, 87648672 Mayet", "payment_date"=>"09:25:14 Nov 09, 2011 PST", "payment_status"=>"Completed", "charset"=>"windows-1252", "address_zip"=>"75002", "mc_shipping"=>"0.00", "mc_handling"=>"0.00", "first_name"=>"Test", "mc_fee"=>"10.01", "address_country_code"=>"FR", "address_name"=>"Test User", "notify_version"=>"3.4", "custom"=>"", "payer_status"=>"verified", "business"=>"syl_1315650606_biz@bellino.fr", "address_country"=>"France", "num_cart_items"=>"1", "mc_handling1"=>"0.00", "address_city"=>"Paris", "verify_sign"=>"AwOJnPNRFHZdnSqc35Btm-KkMwvbA-NWFOONFl0sDe.h8qfGzX3T3iVE", "payer_email"=>"sylvai_1320835836_per@bellino.fr", "mc_shipping1"=>"0.00", "txn_id"=>"67D29474V1031193M", "payment_type"=>"instant", "last_name"=>"User", "address_state"=>"Alsace", "item_name1"=>"Blopsters", "receiver_email"=>"syl_1315650606_biz@bellino.fr", "payment_fee"=>"", "quantity1"=>"2", "receiver_id"=>"VENU3QCG22URG", "txn_type"=>"cart", "mc_gross_1"=>"240.00", "mc_currency"=>"EUR", "residence_country"=>"FR", "test_ipn"=>"1", "transaction_subject"=>"Shopping CartBlopsters", "payment_gross"=>"", "ipn_track_id"=>"1HUPu0oG.fhexChWw61WQA", "secret"=>"testsecret"}
Collection Load (0.6ms) SELECT `collections`.* FROM `collections`
BijouType Load (0.2ms) SELECT `bijou_types`.* FROM `bijou_types`
SQL (0.2ms) BEGIN
AREL (0.6ms) INSERT INTO `carts` (`purchased_at`, `status`, `created_at`, `updated_at`) VALUES (NULL, 'Panier', '2011-11-09 17:25:18', '2011-11-09 17:25:18')
SQL (12.4ms) COMMIT
Before actualize
AREL (13.6ms) UPDATE `carts` SET `updated_at` = '2011-11-09 17:25:18' WHERE (`carts`.`id` = 37)
LineItem Load (0.6ms) SELECT `line_items`.* FROM `line_items` WHERE (`line_items`.cart_id = 37)
After actualize
SQL (0.2ms) BEGIN
SQL (0.7ms) describe `notification_paiements`
AREL (0.4ms) INSERT INTO `notification_paiements` (`params`, `cart_id`, `status`, `transaction_id`, `created_at`, `updated_at`) VALUES ('--- !map:ActiveSupport::HashWithIndifferentAccess \nmc_gross: \"287.04\"\ninvoice: \"36\"\nprotection_eligibility: Ineligible\naddress_status: unconfirmed\nitem_number1: \"1\"\npayer_id: N9JJ8RH7BM8EU\ntax: \"47.04\"\naddress_street: Av. de la Pelouse, 87648672 Mayet\npayment_date: 09:25:14 Nov 09, 2011 PST\npayment_status: Completed\ncharset: windows-1252\naddress_zip: \"75002\"\nmc_shipping: \"0.00\"\nmc_handling: \"0.00\"\nfirst_name: Test\nmc_fee: \"10.01\"\naddress_country_code: FR\naddress_name: Test User\nnotify_version: \"3.4\"\ncustom: \"\"\npayer_status: verified\nbusiness: syl_1315650606_biz@bellino.fr\naddress_country: France\nnum_cart_items: \"1\"\nmc_handling1: \"0.00\"\naddress_city: Paris\nverify_sign: AwOJnPNRFHZdnSqc35Btm-KkMwvbA-NWFOONFl0sDe.h8qfGzX3T3iVE\npayer_email: sylvai_1320835836_per@bellino.fr\nmc_shipping1: \"0.00\"\ntxn_id: 67D29474V1031193M\npayment_type: instant\nlast_name: User\naddress_state: Alsace\nitem_name1: Blopsters\nreceiver_email: syl_1315650606_biz@bellino.fr\npayment_fee: \"\"\nquantity1: \"2\"\nreceiver_id: VENU3QCG22URG\ntxn_type: cart\nmc_gross_1: \"240.00\"\nmc_currency: EUR\nresidence_country: FR\ntest_ipn: \"1\"\ntransaction_subject: Shopping CartBlopsters\npayment_gross: \"\"\nipn_track_id: 1HUPu0oG.fhexChWw61WQA\nsecret: testsecret\naction: create\ncontroller: notification_paiements\n', 36, 'Completed', '67D29474V1031193M', '2011-11-09 17:25:18', '2011-11-09 17:25:18')
SQL (3.3ms) COMMIT
Rendered text template (0.0ms)
Completed 200 OK in 96ms (Views: 20.4ms | ActiveRecord: 32.7ms)

如您所见,来自 paypal 的信息通过插入存储在 notification_paiements 表中。

现在一个非paypal用户unsing paypal支付:

Started POST "/notification_paiements?secret=testsecret" for 173.0.82.126 at 2011-11-09 18:39:01 +0100
Processing by NotificationPaiementsController#create as HTML
Parameters: {"mc_gross"=>"143.52", "invoice"=>"38", "protection_eligibility"=>"Ineligible", "address_status"=>"unconfirmed", "item_number1"=>"1", "payer_id"=>"TVV27PV4CE9WN", "tax"=>"23.52", "address_street"=>"1 Rue moli\xE8re", "payment_date"=>"09:28:02 Nov 09, 2011 PST", "payment_status"=>"Completed", "charset"=>"windows-1252", "address_zip"=>"06000", "mc_shipping"=>"0.00", "mc_handling"=>"0.00", "first_name"=>"Sylvain", "mc_fee"=>"5.13", "address_country_code"=>"FR", "address_name"=>"Sylvain Bellino", "notify_version"=>"3.4", "custom"=>"", "payer_status"=>"unverified", "business"=>"syl_1315650606_biz@bellino.fr", "address_country"=>"France", "num_cart_items"=>"1", "mc_handling1"=>"0.00", "address_city"=>"Quinper", "verify_sign"=>"AqbqXETD.PxAAbSmxayIN78tg6E5A8bGf00DQNeRfx1TbcIGu8oSrIKM", "payer_email"=>"test@test.com", "mc_shipping1"=>"0.00", "txn_id"=>"7L144405TP446563S", "payment_type"=>"instant", "last_name"=>"Bellino", "address_state"=>"", "item_name1"=>"Blopsters", "receiver_email"=>"syl_1315650606_biz@bellino.fr", "payment_fee"=>"", "quantity1"=>"1", "receiver_id"=>"VENU3QCG22URG", "txn_type"=>"cart", "mc_gross_1"=>"120.00", "mc_currency"=>"EUR", "residence_country"=>"FR", "test_ipn"=>"1", "receipt_id"=>"4652-2775-4616-8599", "transaction_subject"=>"Shopping CartBlopsters", "payment_gross"=>"", "ipn_track_id"=>"gfqdiv.LSFZQPO3RomLrBw", "secret"=>"testsecret"}
Collection Load (0.4ms) SELECT `collections`.* FROM `collections`
BijouType Load (0.1ms) SELECT `bijou_types`.* FROM `bijou_types`
SQL (0.1ms) BEGIN
SQL (0.7ms) SHOW TABLES
SQL (0.6ms) describe `carts`
AREL (0.6ms) INSERT INTO `carts` (`purchased_at`, `status`, `created_at`, `updated_at`) VALUES (NULL, 'Panier', '2011-11-09 17:39:01', '2011-11-09 17:39:01')
SQL (7.0ms) COMMIT
Before actualize
AREL (10.1ms) UPDATE `carts` SET `updated_at` = '2011-11-09 17:39:01' WHERE (`carts`.`id` = 45)
LineItem Load (0.7ms) SELECT `line_items`.* FROM `line_items` WHERE (`line_items`.cart_id = 45)
After actualize
SQL (0.2ms) BEGIN
SQL (0.1ms) ROLLBACK
Completed in 134ms

当它应该在数据库中创建条目时发生某种回滚。

Controller 的代码相当简单:

class NotificationPaiementsController < ApplicationController
protect_from_forgery :except =>[:create]
skip_before_filter :authorize, :only => [:create]

def create
@notification_paiement = NotificationPaiement.create!(:params => params,
:cart_id => params[:invoice],
:status=> params[:payment_status], :transaction_id => params[:txn_id])
render :nothing=>true
end
end

在创建方法中发生了一些阻止记录某些通知的事情,但是什么?有没有办法拥有更冗长的创建方法?

最佳答案

问题出在像 : é 这样的特殊字符上

该应用程序是完整的 UTF-8(包括 mysql UTF-8 兼容的 ruby​​ 驱动程序和 UTF-8 中的 MySQL)。

要在 utf 8 中设置 IPN,请执行以下操作:

ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
vparams = {}
params.each do |k,v|
vparams[k]=v.force_encoding('ISO-8859-1').encode!('UTF-8')
end

关于ruby-on-rails - 我收到了 Paypal IPN 罚款,但我的应用程序仅在从 paypal 帐户完成时才记录它。由 UTF-8/ISO-8859-1 引起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8069449/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com