Я пытаюсь интегрировать подписки paddle.com в свое приложение Rails
Вот код
require 'base64'
require 'php_serialize'
require 'openssl'
class SubscriptionsController < ApplicationController
skip_before_action :verify_authenticity_token
def check
public_key = "-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAr7/mDtqUWyh2bb2QSkUE
PAPP7pwc6RhQrf9ikKVmssNTn0bDUcOi5dDhWON2u1xpAl6OMAX9lCPY7saHqzJR
MQrj0D3EmKDcXTBFnQWEOx4pToxhGsjpahGnq0kOtlig+1zFyYz78Wn3a58dxTIi
m1K6MOHj7R8TP2k6haLE8ZECAwEAAQ==
-----END PUBLIC KEY-----"
if request.headers['Content-Type'] == 'application/json'
data = JSON.parse(request.body.read)
else
data = params.as_json
end
signature = Base64.decode64(data['p_signature'])
data.delete('p_signature')
data.each {|key, value|data[key] = String(value)}
data_sorted = data.sort_by{|key, value| key}
data_serialized = PHP.serialize(data_sorted, true)
digest = OpenSSL::Digest::SHA1.new
pub_key = OpenSSL::PKey::RSA.new(public_key).public_key
verified = pub_key.verify(digest, signature, data_serialized)
if verified
puts 'Yay ok'
head :ok
else
puts 'The signature is invalid!'
end
end
end
Я тестирую его с помощью симулятора вебхука Paddle, но я получил ошибку - недействительная подпись. «Подпись недействительна», что означает невозможность проверки
Processing by SubscriptionsController#check as */*
Parameters: {"user_id"=>"1", "p_signature"=>"WXY2kaJc12zmM9ZkpKt5IHpmknG6cEOBmtWlEGtY/PPrOvDXcfQnRbW0iNSRGEpSp9oWzkHOGxnFRW3P+fiEmSJnsDU+8SdbMB8b7S4Wc5U8Ld7pv9t5oCpHiJI3HWeUrwWMpJz/vOMRiqHQxM6iBT/LCzgrbVNYuzYQRIModbODJ2L8spu5oqlP10CTHyFsEVw8t3PAvVsaNPobZvU9cLNhDpNi1fyuqUQ6nPP0xX6xo/iewoL16gSMWhQw11saC/XssxSktDdszAa+f5cl/6sN5IqfVOfTGNiYc6M0DEG6OQ+tGX9xt4MmUju3H7W4BzQ6g68t5dFXjmfigaq+vf5K7PTxrX99AJPx1XR6lIwdp/9A2lBYPpcAVdIeESaugzlKrkMm3vmi2idnSW9XawJPDykIUPwVyrVmkcabNWeMVBtBNM4BhTqCPe4McNKm02en5gUMdokFCsljRwm9Ut5cP7hrIP8RtXQDj650WB1Uf6Q3EW0UYzJM9yv8nMiJHDWYF0RSlI8qJkIBOzf6j2Ykl4QVT6hAmfXVHID70I9Okq9v0GAZEY8wX3gOPUqBr6JNxVVCO1eaqDchSR6IN0s2q8dm5UWSk5ugDIRY7/6wLj5+01efHTW9xq24FMHvDwfVzGk5Q2JA7/LMyn59SHcAasz8UJGaITl/iSqaZkA="}
The signature is invalid!
No template found for SubscriptionsController#check, rendering head :no_content
Completed 204 No Content in 26ms (ActiveRecord: 0.0ms)
Как я могу это проверить?
Paddle docs здесь