sepay_pg_ruby
Ruby SDK cho SePay Payment Gateway, dùng cho Rails project.
Cài đặt trong Rails
Trong Gemfile:
gem 'sepay_pg_ruby', path: 'gem/sepay_pg_ruby'
Sau đó chạy:
bundle install
Khởi tạo client
client = SepayPgRuby::Client.new(
env: Rails.env.production? ? 'production' : 'sandbox',
merchant_id: ENV.fetch('SEPAY_MERCHANT_ID'),
secret_key: ENV.fetch('SEPAY_SECRET_KEY')
)
Orders API
# Danh sách orders
client.order.all(per_page: 20, q: 'ORDER-001')
# Chi tiết order
client.order.retrieve('ORDER-001')
# Void transaction
client.order.void_transaction('ORDER-001')
# Cancel order
client.order.cancel('ORDER-001')
Checkout API
checkout_url = client.checkout.init_checkout_url
fields = client.checkout.init_one_time_payment_fields(
order_invoice_number: 'ORDER-001',
order_amount: 100_000,
currency: 'VND',
order_description: 'Thanh toan don hang ORDER-001',
payment_method: 'BANK_TRANSFER',
success_url: 'https://your-app.com/payment/success',
error_url: 'https://your-app.com/payment/error',
cancel_url: 'https://your-app.com/payment/cancel'
)
Verify IPN signature
is_valid = SepayPgRuby::IPN.verify_signature(params.to_unsafe_h, ENV['SEPAY_SECRET_KEY'])