Skip to content

Laravel Cashier (Paddle)

Nguồn gốc: Bản dịch từ Laravel Cashier (Paddle)

Giới thiệu (Introduction)

GỢI Ý

Tài liệu này dành cho Cashier Paddle 2.x tích hợp với Paddle Billing. Nếu vẫn dùng Paddle Classic, hãy dùng Cashier Paddle 1.x.

Laravel Cashier Paddle cung cấp interface diễn đạt, fluent cho dịch vụ subscription billing của Paddle. Nó xử lý gần như toàn bộ boilerplate billing code. Ngoài quản lý subscription cơ bản, Cashier còn xử lý: swap subscription, subscription "quantities", tạm dừng subscription, grace period hủy, và nhiều tính năng khác.

Trước khi tìm hiểu sâu, nên xem thêm concept guidesAPI documentation của Paddle.

Cài đặt (Installation)

bash
composer require laravel/cashier-paddle

Publish migration:

bash
php artisan vendor:publish --tag="cashier-migrations"

Chạy migration:

bash
php artisan migrate

Migration tạo bảng customers, subscriptions, subscription_itemstransactions.

Paddle Sandbox

Sử dụng môi trường Paddle Sandbox để phát triển và testing.

Cấu hình (Configuration)

Billable Model

Thêm trait Billable vào model user.

API Keys

Cấu hình Paddle API keys trong .env.

Paddle JS

Paddle sử dụng thư viện JavaScript riêng để khởi tạo Paddle Checkout widget.

Currency Configuration

Tiền tệ mặc định là USD, có thể tùy chỉnh qua biến môi trường.

Quickstart

  • Selling Products — Bán sản phẩm qua Paddle Checkout
  • Selling Subscriptions — Bán subscription định kỳ

Checkout Sessions

  • Overlay Checkout — Checkout dạng overlay popup
  • Inline Checkout — Checkout nhúng trực tiếp
  • Guest Checkouts — Checkout cho khách chưa đăng ký

Price Previews

  • Customer Price Previews — Xem trước giá theo customer
  • Discounts — Áp dụng mã giảm giá

Customers

  • Customer Defaults — Thiết lập mặc định
  • Retrieving Customers — Lấy thông tin
  • Creating Customers — Tạo customer mới

Subscriptions

  • Creating Subscriptions — Tạo subscription
  • Checking Status — Kiểm tra trạng thái
  • Subscription Single Charges — Tính phí bổ sung
  • Changing Plans — Đổi gói
  • Subscription Quantity — Quản lý số lượng
  • Multiple Products / Subscriptions — Nhiều gói
  • Pausing / Canceling — Tạm dừng / Hủy

Subscription Trials

  • With Payment Method Up Front — Trial yêu cầu thanh toán
  • Without Payment Method Up Front — Trial miễn phí
  • Extend or Activate a Trial — Gia hạn trial

Xử lý Paddle Webhooks

Cashier tự động xử lý webhook. Có thể định nghĩa thêm handler và xác thực signature.

Single Charges

  • Charging for Products — Tính phí sản phẩm
  • Refunding / Crediting Transactions — Hoàn tiền / Credit

Transactions

  • Lấy danh sách transaction
  • Past and upcoming payments

Testing

Sử dụng Paddle Sandbox cho testing.