Проблема: force_encoding ('UTF-8') создает недопустимую кодировку при попытке проверить событие PayPal Webhook. Валидная часть сертификата работает нормально. См. Изображение Неверная кодировка
Код
module Webhooks
class PaypalController < ApplicationController
skip_before_action :authorize_request
def hook
actual_signature = request.headers["Paypal-Transmission-Sig"]
auth_algo = request.headers["Paypal-Auth-Algo"]
auth_algo.sub!(/withRSA/i, "")
cert_url = request.headers["Paypal-Cert-Url"]
transmission_id = request.headers["Paypal-Transmission-Id"]
timestamp = request.headers["Paypal-Transmission-Time"]
webhook_id = "0PC33693PD324571U"
event_body = params["paypal"].to_json
valid = PayPal::SDK::REST::WebhookEvent.verify(transmission_id, timestamp, webhook_id, event_body, cert_url, actual_sig, auth_algo)
end
end
end
Переменные
actual_signature = FQlzVbTx82BOOQMuvNEgldHHik0q0TQR0ZwrsGXCVZnJYbaFrDOrzTG1/cn0SCNDcQxEsu+hR7feu14jnHC452ACEyDqYk2IeOIjzo2RDZ5S9FMZJ56Kv7uMyLZDui16pUlB1MqZWzQVXYSR0O+hHW7pwzBoxR3YY0UOALmv0eMJ5aDK5YBJokCNkUJMpEhcPmkKGjAR1KqV6swS+2PMqxawfylPl2/I20agKjSDm7QsMXvaQZl7hm613n9s6yqBpsbzgESlvzo1Ri6VafznydJ82xpP0M+3iQLpcKzzPj3wDpzaDmR7r1zhg9Hd2eg037qDYoip6p5nCzm/c9klnQ==
auth_algo = SHA256
cert_url = https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-1d93a270
transmission_id = 0c1badf0-4c1b-11ea-bda8-1d900e460095
timestamp = 2020-02-10T15:36:03Z
webhook_id = 0PC33693PD324571U
event_body = {"id":"WH-2YT23629NU5635806-66L81914W2515435K","event_version":"1.0","create_time":"2020-02-10T15:35:55.420Z","resource_type":"payment","event_type":"PAYMENTS.PAYMENT.CREATED","summary":"Checkout payment is created and approved by buyer","resource":{"update_time":"2020-02-10T15:35:55Z","create_time":"2020-02-10T15:35:14Z","redirect_urls":{"return_url":"http://localhost/payment/execute?paymentId=PAYID-LZAXQMY86E71517DB986120J","cancel_url":"http://localhost:3000/"},"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAYID-LZAXQMY86E71517DB986120J","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAYID-LZAXQMY86E71517DB986120J/execute","rel":"execute","method":"POST"},{"href":"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout\u0026token=EC-36U942266G8017214","rel":"approval_url","method":"REDIRECT"}],"id":"PAYID-LZAXQMY86E71517DB986120J","state":"created","transactions":[{"amount":{"total":"5.50","currency":"USD"},"payee":{"merchant_id":"P3DN8UTLQR3AY","email":"sb-ysww0997817@business.example.com"},"description":"Sale","item_list":{"shipping_address":{"recipient_name":"John Doe","line1":"1 Main St","city":"San Jose","state":"CA","postal_code":"95131","country_code":"US","default_address":false,"preferred_address":false,"primary_address":false,"disable_for_transaction":false}},"related_resources":[]}],"intent":"sale","payer":{"payment_method":"paypal","status":"VERIFIED","payer_info":{"email":"sb-d8kwi996334@personal.example.com","first_name":"John","last_name":"Doe","payer_id":"6WZKWRGAWJ9T6","shipping_address":{"recipient_name":"John Doe","line1":"1 Main St","city":"San Jose","state":"CA","postal_code":"95131","country_code":"US","default_address":false,"preferred_address":false,"primary_address":false,"disable_for_transaction":false},"country_code":"US"}},"cart":"36U942266G8017214"},"links":[{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-2YT23629NU5635806-66L81914W2515435K","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-2YT23629NU5635806-66L81914W2515435K/resend","rel":"resend","method":"POST"}]}