API đăng ký Stripe cung cấp một cách dễ dàng để tích hợp các khoản thanh toán định kỳ trên trang web. Nếu bạn muốn triển khai hệ thống đăng ký thành viên trên ứng dụng web, thì cần phải thanh toán đăng ký để thanh toán định kỳ. Cổng thanh toán Stripe giúp tích hợp thanh toán định kỳ với Gói và API đăng ký. Đăng ký sọc là một cách nhanh chóng và hiệu quả để cho phép các thành viên trang web của bạn mua tư cách thành viên trực tuyến bằng thẻ tín dụng của họ
Trong thanh toán đăng ký Stripe, người mua bị tính phí định kỳ dựa trên khoảng thời gian cụ thể. Thành viên của trang web của bạn có thể đăng ký gói và thanh toán bằng thẻ tín dụng/thẻ ghi nợ của họ mà không cần rời khỏi trang web. Trong hướng dẫn này, chúng tôi sẽ chỉ cho bạn cách tích hợp thanh toán đăng ký Stripe bằng PHP
Trong tập lệnh ví dụ, chúng tôi sẽ triển khai chức năng sau để chấp nhận thanh toán cho đăng ký qua Cổng thanh toán Stripe bằng PHP
- Tạo biểu mẫu HTML để chọn gói đăng ký và cung cấp thông tin thẻ tín dụng
- Đính kèm phần tử thẻ Stripe vào biểu mẫu HTML bằng thư viện Stripe JS
- Truyền chi tiết thẻ, xác thực và tạo đăng ký một cách an toàn với Stripe API
- Truy xuất PaymentIntent và thông tin đăng ký bằng Stripe API
- Xác nhận thanh toán bằng thẻ với xác thực 3D Secure hỗ trợ quy trình Xác thực khách hàng mạnh mẽ [SCA]
- Xác minh thẻ và tạo gói đăng ký với Stripe API
- Lưu trữ dữ liệu giao dịch với chi tiết đăng ký trong cơ sở dữ liệu và hiển thị trạng thái thanh toán
Trước khi bắt đầu tích hợp API thanh toán đăng ký Stripe trong PHP, hãy xem cấu trúc tệp
stripe_subscription_payment_php/ ├── config.php ├── dbConnect.php ├── index.php ├── payment_init.php ├── payment-status.php ├── stripe-php/ ├── js/ | └── checkout.js └── css/ └── style.css
Khóa API kiểm tra sọc
Trước khi làm cho cổng thanh toán đăng ký Stripe hoạt động, cần phải kiểm tra xem quy trình đăng ký có hoạt động bình thường không. Bạn cần dữ liệu khóa API thử nghiệm để kiểm tra quy trình thanh toán đăng ký
- Đăng nhập vào tài khoản Stripe của bạn và điều hướng đến trang Nhà phát triển » Khóa API
- Trong khối DỮ LIỆU KIỂM TRA, bạn sẽ thấy các khóa API [Khóa có thể xuất bản và Khóa bí mật] được liệt kê trong phần Khóa tiêu chuẩn. Để hiển thị Khóa bí mật, hãy nhấp vào nút Hiển thị mã thông báo khóa kiểm tra.
Thu thập khóa Có thể xuất bản và khóa Bí mật để sử dụng sau này trong tập lệnh
Tạo bảng cơ sở dữ liệu
Để lưu trữ thông tin về gói, thành viên và đăng ký, cần có 3 bảng trong cơ sở dữ liệu
1. SQL sau đây tạo một bảng
CREATE TABLE `plans` [ `id` int[11] NOT NULL AUTO_INCREMENT, `name` varchar[255] COLLATE utf8_unicode_ci NOT NULL, `price` float[10,2] NOT NULL DEFAULT 0.00 COMMENT 'Minimum amount is $0.50 US', `interval` enum['week','month','year'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'month', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;3 để chứa thông tin gói thuê bao trong cơ sở dữ liệu MySQL
CREATE TABLE `plans` [ `id` int[11] NOT NULL AUTO_INCREMENT, `name` varchar[255] COLLATE utf8_unicode_ci NOT NULL, `price` float[10,2] NOT NULL DEFAULT 0.00 COMMENT 'Minimum amount is $0.50 US', `interval` enum['week','month','year'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'month', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
2. SQL sau đây tạo một bảng
CREATE TABLE `plans` [ `id` int[11] NOT NULL AUTO_INCREMENT, `name` varchar[255] COLLATE utf8_unicode_ci NOT NULL, `price` float[10,2] NOT NULL DEFAULT 0.00 COMMENT 'Minimum amount is $0.50 US', `interval` enum['week','month','year'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'month', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;4 để chứa thông tin của thành viên trong cơ sở dữ liệu MySQL
CREATE TABLE `users` [ `id` int[11] NOT NULL AUTO_INCREMENT, `subscription_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "user_subscriptions" table', `first_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `last_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `email` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `password` varchar[255] COLLATE utf8_unicode_ci DEFAULT NULL, `phone` varchar[15] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL DEFAULT current_timestamp[], `modified` datetime NOT NULL DEFAULT current_timestamp[], `status` tinyint[1] NOT NULL DEFAULT 1 COMMENT '1=Active | 0=Inactive', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3. SQL sau đây tạo một bảng
CREATE TABLE `plans` [ `id` int[11] NOT NULL AUTO_INCREMENT, `name` varchar[255] COLLATE utf8_unicode_ci NOT NULL, `price` float[10,2] NOT NULL DEFAULT 0.00 COMMENT 'Minimum amount is $0.50 US', `interval` enum['week','month','year'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'month', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;5 để chứa thông tin đăng ký trong cơ sở dữ liệu MySQL
CREATE TABLE `user_subscriptions` [ `id` int[11] NOT NULL AUTO_INCREMENT, `user_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "users" table', `plan_id` int[5] DEFAULT NULL COMMENT 'foreign key of "plans" table', `payment_method` enum['stripe'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'stripe', `stripe_subscription_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_customer_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_payment_intent_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `paid_amount` float[10,2] NOT NULL, `paid_amount_currency` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval_count` tinyint[2] NOT NULL DEFAULT 1, `customer_name` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `customer_email` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL, `plan_period_start` datetime DEFAULT NULL, `plan_period_end` datetime DEFAULT NULL, `status` varchar[50] COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Trước khi tiếp tục, hãy thêm một số dữ liệu vào bảng
CREATE TABLE `plans` [ `id` int[11] NOT NULL AUTO_INCREMENT, `name` varchar[255] COLLATE utf8_unicode_ci NOT NULL, `price` float[10,2] NOT NULL DEFAULT 0.00 COMMENT 'Minimum amount is $0.50 US', `interval` enum['week','month','year'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'month', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;3 của cơ sở dữ liệu để người dùng có thể chọn gói đăng ký của họ________số 8_______
Stripe API và cấu hình cơ sở dữ liệu [config. php]
Trong tệp
CREATE TABLE `plans` [ `id` int[11] NOT NULL AUTO_INCREMENT, `name` varchar[255] COLLATE utf8_unicode_ci NOT NULL, `price` float[10,2] NOT NULL DEFAULT 0.00 COMMENT 'Minimum amount is $0.50 US', `interval` enum['week','month','year'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'month', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;7, các biến cố định được xác định cho cài đặt cơ sở dữ liệu và API Stripe
Hằng số API sọc
- STRIPE_API_KEY – Chỉ định khóa Bí mật API
- STRIPE_PUBLISHABLE_KEY – Chỉ định khóa API có thể xuất bản
- STRIPE_CURRENCY – Mã tiền tệ
Hằng cơ sở dữ liệu
- DB_HOST – Chỉ định máy chủ lưu trữ cơ sở dữ liệu
- DB_USERNAME – Chỉ định tên người dùng cơ sở dữ liệu
- DB_PASSWORD – Chỉ định mật khẩu cơ sở dữ liệu
- DB_NAME – Chỉ định tên cơ sở dữ liệu
/* Stripe API configuration
* Remember to switch to your live publishable and secret key in production!
* See your keys here: //dashboard.stripe.com/account/apikeys
*/
define['STRIPE_API_KEY', 'Your_API_Secret_key'];
define['STRIPE_PUBLISHABLE_KEY', 'Your_API_Publishable_key'];
define['STRIPE_CURRENCY', 'USD'];// Database configuration
define['DB_HOST', 'MySQL_Database_Host'];
define['DB_USERNAME', 'MySQL_Database_Username'];
define['DB_PASSWORD', 'MySQL_Database_Password'];
define['DB_NAME', 'MySQL_Database_Name'];
Lưu ý rằng. Khóa bí mật API Stripe và khóa có thể xuất bản sẽ được tìm thấy trong phần Dữ liệu khóa API trong tài khoản Stripe của bạn
Kết nối cơ sở dữ liệu [dbConnect. php]
File
CREATE TABLE `plans` [ `id` int[11] NOT NULL AUTO_INCREMENT, `name` varchar[255] COLLATE utf8_unicode_ci NOT NULL, `price` float[10,2] NOT NULL DEFAULT 0.00 COMMENT 'Minimum amount is $0.50 US', `interval` enum['week','month','year'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'month', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;8 dùng để kết nối cơ sở dữ liệu bằng PHP và MySQL
// Connect with the database
$db = new mysqli[DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME];// Display error if failed to connect
if [$db->connect_errno] {
printf["Connect failed: %s\n", $db->connect_error];
exit[];
}
Biểu mẫu đăng ký sọc [chỉ mục. php]
Bao gồm các tệp cấu hình và tìm nạp các gói đăng ký từ cơ sở dữ liệu
// Include configuration file
require_once 'config.php';// Include the database connection file
include_once 'dbConnect.php';// Fetch plans from the database
$sqlQ = "SELECT * FROM plans";
$stmt = $db->prepare[$sqlQ];
$stmt->execute[];
$stmt->store_result[];
?>
Thư viện Stripe JS
bao gồm sọc. thư viện js v3 giúp gửi an toàn thông tin nhạy cảm tới Stripe trực tiếp từ trình duyệt
Thanh toán tập lệnh JS
Bao gồm tập lệnh tùy chỉnh [
CREATE TABLE `plans` [ `id` int[11] NOT NULL AUTO_INCREMENT, `name` varchar[255] COLLATE utf8_unicode_ci NOT NULL, `price` float[10,2] NOT NULL DEFAULT 0.00 COMMENT 'Minimum amount is $0.50 US', `interval` enum['week','month','year'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'month', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;9] để xử lý đăng ký với Stripe API bằng JavaScript
- Thuộc tính
CREATE TABLE `users` [ `id` int[11] NOT NULL AUTO_INCREMENT, `subscription_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "user_subscriptions" table', `first_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `last_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `email` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `password` varchar[255] COLLATE utf8_unicode_ci DEFAULT NULL, `phone` varchar[15] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL DEFAULT current_timestamp[], `modified` datetime NOT NULL DEFAULT current_timestamp[], `status` tinyint[1] NOT NULL DEFAULT 1 COMMENT '1=Active | 0=Inactive', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
0 được sử dụng để chuyển Khóa API Stripe cho tập lệnh JS
Biểu mẫu đăng ký HTML
Ban đầu, tất cả các gói được liệt kê trong hộp chọn thả xuống và một biểu mẫu HTML được xác định để thu thập thông tin người dùng [tên và email] và chi tiết thẻ [Số thẻ, Ngày hết hạn và Số CVC]. ]
- Xác định một phần tử HTML [
CREATE TABLE `users` [ `id` int[11] NOT NULL AUTO_INCREMENT, `subscription_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "user_subscriptions" table', `first_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `last_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `email` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `password` varchar[255] COLLATE utf8_unicode_ci DEFAULT NULL, `phone` varchar[15] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL DEFAULT current_timestamp[], `modified` datetime NOT NULL DEFAULT current_timestamp[], `status` tinyint[1] NOT NULL DEFAULT 1 COMMENT '1=Active | 0=Inactive', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1] để đính kèm các phần tử thẻ theo sọc. thư viện js - Xác định phần tử để hiển thị thông báo xử lý thanh toán
Tập lệnh xử lý thanh toán đăng ký [thanh toán. js]
Mã JavaScript sau đây được sử dụng để xử lý quy trình đăng ký với thư viện Stripe JS v3
- Tạo một phiên bản của đối tượng Stripe và đặt khóa API có thể xuất bản
- Tạo phần tử thẻ và gắn thẻElement vào phần tử HTML [
CREATE TABLE `users` [ `id` int[11] NOT NULL AUTO_INCREMENT, `subscription_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "user_subscriptions" table', `first_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `last_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `email` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `password` varchar[255] COLLATE utf8_unicode_ci DEFAULT NULL, `phone` varchar[15] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL DEFAULT current_timestamp[], `modified` datetime NOT NULL DEFAULT current_timestamp[], `status` tinyint[1] NOT NULL DEFAULT 1 COMMENT '1=Active | 0=Inactive', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1] - Đính kèm trình xử lý sự kiện [handleSubscrSubmit] vào biểu mẫu đăng ký
- hàm handleSubscrSubmit[] được sử dụng để,
- Đăng ID gói đã chọn và chi tiết khách hàng vào tập lệnh phía máy chủ [
CREATE TABLE `users` [ `id` int[11] NOT NULL AUTO_INCREMENT, `subscription_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "user_subscriptions" table', `first_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `last_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `email` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `password` varchar[255] COLLATE utf8_unicode_ci DEFAULT NULL, `phone` varchar[15] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL DEFAULT current_timestamp[], `modified` datetime NOT NULL DEFAULT current_timestamp[], `status` tinyint[1] NOT NULL DEFAULT 1 COMMENT '1=Active | 0=Inactive', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3] - Tải phương thức
CREATE TABLE `users` [ `id` int[11] NOT NULL AUTO_INCREMENT, `subscription_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "user_subscriptions" table', `first_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `last_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `email` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `password` varchar[255] COLLATE utf8_unicode_ci DEFAULT NULL, `phone` varchar[15] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL DEFAULT current_timestamp[], `modified` datetime NOT NULL DEFAULT current_timestamp[], `status` tinyint[1] NOT NULL DEFAULT 1 COMMENT '1=Active | 0=Inactive', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
4 và vượt quaCREATE TABLE `users` [ `id` int[11] NOT NULL AUTO_INCREMENT, `subscription_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "user_subscriptions" table', `first_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `last_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `email` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `password` varchar[255] COLLATE utf8_unicode_ci DEFAULT NULL, `phone` varchar[15] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL DEFAULT current_timestamp[], `modified` datetime NOT NULL DEFAULT current_timestamp[], `status` tinyint[1] NOT NULL DEFAULT 1 COMMENT '1=Active | 0=Inactive', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
5 & Mục đích thanh toánCREATE TABLE `users` [ `id` int[11] NOT NULL AUTO_INCREMENT, `subscription_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "user_subscriptions" table', `first_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `last_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `email` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `password` varchar[255] COLLATE utf8_unicode_ci DEFAULT NULL, `phone` varchar[15] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL DEFAULT current_timestamp[], `modified` datetime NOT NULL DEFAULT current_timestamp[], `status` tinyint[1] NOT NULL DEFAULT 1 COMMENT '1=Active | 0=Inactive', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
6 trong đó
- Đăng ID gói đã chọn và chi tiết khách hàng vào tập lệnh phía máy chủ [
- hàm paymentProcess[] được sử dụng để,
- Xác nhận ý định thanh toán bằng cách sử dụng
CREATE TABLE `users` [ `id` int[11] NOT NULL AUTO_INCREMENT, `subscription_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "user_subscriptions" table', `first_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `last_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `email` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `password` varchar[255] COLLATE utf8_unicode_ci DEFAULT NULL, `phone` varchar[15] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL DEFAULT current_timestamp[], `modified` datetime NOT NULL DEFAULT current_timestamp[], `status` tinyint[1] NOT NULL DEFAULT 1 COMMENT '1=Active | 0=Inactive', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
7 trong số JS API ý định thanh toán của Stripe - Đăng thông tin đăng ký và giao dịch lên tập lệnh phía máy chủ [_______4_______3] và chuyển hướng đến trang trạng thái thanh toán [
CREATE TABLE `users` [ `id` int[11] NOT NULL AUTO_INCREMENT, `subscription_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "user_subscriptions" table', `first_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `last_name` varchar[25] COLLATE utf8_unicode_ci NOT NULL, `email` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `password` varchar[255] COLLATE utf8_unicode_ci DEFAULT NULL, `phone` varchar[15] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL DEFAULT current_timestamp[], `modified` datetime NOT NULL DEFAULT current_timestamp[], `status` tinyint[1] NOT NULL DEFAULT 1 COMMENT '1=Active | 0=Inactive', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
9]
- Xác nhận ý định thanh toán bằng cách sử dụng
- Hàm
CREATE TABLE `user_subscriptions` [ `id` int[11] NOT NULL AUTO_INCREMENT, `user_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "users" table', `plan_id` int[5] DEFAULT NULL COMMENT 'foreign key of "plans" table', `payment_method` enum['stripe'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'stripe', `stripe_subscription_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_customer_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_payment_intent_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `paid_amount` float[10,2] NOT NULL, `paid_amount_currency` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval_count` tinyint[2] NOT NULL DEFAULT 1, `customer_name` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `customer_email` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL, `plan_period_start` datetime DEFAULT NULL, `plan_period_end` datetime DEFAULT NULL, `status` varchar[50] COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
0 giúp hiển thị thông báo trạng thái - Chức năng
CREATE TABLE `user_subscriptions` [ `id` int[11] NOT NULL AUTO_INCREMENT, `user_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "users" table', `plan_id` int[5] DEFAULT NULL COMMENT 'foreign key of "plans" table', `payment_method` enum['stripe'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'stripe', `stripe_subscription_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_customer_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_payment_intent_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `paid_amount` float[10,2] NOT NULL, `paid_amount_currency` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval_count` tinyint[2] NOT NULL DEFAULT 1, `customer_name` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `customer_email` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL, `plan_period_start` datetime DEFAULT NULL, `plan_period_end` datetime DEFAULT NULL, `status` varchar[50] COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1 vô hiệu hóa nút gửi và hiển thị công cụ quay vòng khi gửi thanh toán - Hàm
CREATE TABLE `user_subscriptions` [ `id` int[11] NOT NULL AUTO_INCREMENT, `user_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "users" table', `plan_id` int[5] DEFAULT NULL COMMENT 'foreign key of "plans" table', `payment_method` enum['stripe'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'stripe', `stripe_subscription_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_customer_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_payment_intent_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `paid_amount` float[10,2] NOT NULL, `paid_amount_currency` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval_count` tinyint[2] NOT NULL DEFAULT 1, `customer_name` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `customer_email` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL, `plan_period_start` datetime DEFAULT NULL, `plan_period_end` datetime DEFAULT NULL, `status` varchar[50] COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
2 vô hiệu hóa biểu mẫu thanh toán và hiển thị thông báo về quá trình xử lý thanh toán
Thư viện sọc PHP
Thư viện Stripe PHP được sử dụng để truy cập API Stripe trong PHP. Nó giúp tạo khách hàng, kế hoạch và đăng ký với Stripe API. Tất cả các tệp thư viện cần thiết đều có trong mã nguồn của chúng tôi, bạn không cần tải xuống riêng
Xử lý thanh toán đăng ký [payment_init. php]
Tập lệnh phía máy chủ này được API tìm nạp phía máy khách truy cập trong mã JavaScript [
CREATE TABLE `user_subscriptions` [ `id` int[11] NOT NULL AUTO_INCREMENT, `user_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "users" table', `plan_id` int[5] DEFAULT NULL COMMENT 'foreign key of "plans" table', `payment_method` enum['stripe'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'stripe', `stripe_subscription_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_customer_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_payment_intent_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `paid_amount` float[10,2] NOT NULL, `paid_amount_currency` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval_count` tinyint[2] NOT NULL DEFAULT 1, `customer_name` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `customer_email` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL, `plan_period_start` datetime DEFAULT NULL, `plan_period_end` datetime DEFAULT NULL, `status` varchar[50] COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;3] để tạo PaymentIntent, đăng ký và xử lý thanh toán bằng thẻ tín dụng bằng thư viện Stripe API PHP
- Bao gồm thư viện Stripe PHP
- Đặt khóa bí mật API bằng phương thức setApiKey[] của lớp Stripe
- Truy xuất JSON từ nội dung POST bằng cách sử dụng
CREATE TABLE `user_subscriptions` [ `id` int[11] NOT NULL AUTO_INCREMENT, `user_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "users" table', `plan_id` int[5] DEFAULT NULL COMMENT 'foreign key of "plans" table', `payment_method` enum['stripe'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'stripe', `stripe_subscription_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_customer_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_payment_intent_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `paid_amount` float[10,2] NOT NULL, `paid_amount_currency` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval_count` tinyint[2] NOT NULL DEFAULT 1, `customer_name` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `customer_email` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL, `plan_period_start` datetime DEFAULT NULL, `plan_period_end` datetime DEFAULT NULL, `status` varchar[50] COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
4 vàCREATE TABLE `user_subscriptions` [ `id` int[11] NOT NULL AUTO_INCREMENT, `user_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "users" table', `plan_id` int[5] DEFAULT NULL COMMENT 'foreign key of "plans" table', `payment_method` enum['stripe'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'stripe', `stripe_subscription_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_customer_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_payment_intent_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `paid_amount` float[10,2] NOT NULL, `paid_amount_currency` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval_count` tinyint[2] NOT NULL DEFAULT 1, `customer_name` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `customer_email` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL, `plan_period_start` datetime DEFAULT NULL, `plan_period_end` datetime DEFAULT NULL, `status` varchar[50] COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
5 trong PHP - Nhận ID người dùng đã đăng nhập từ SESSION
Nếu yêu cầu
CREATE TABLE `user_subscriptions` [ `id` int[11] NOT NULL AUTO_INCREMENT, `user_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "users" table', `plan_id` int[5] DEFAULT NULL COMMENT 'foreign key of "plans" table', `payment_method` enum['stripe'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'stripe', `stripe_subscription_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_customer_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_payment_intent_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `paid_amount` float[10,2] NOT NULL, `paid_amount_currency` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval_count` tinyint[2] NOT NULL DEFAULT 1, `customer_name` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `customer_email` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL, `plan_period_start` datetime DEFAULT NULL, `plan_period_end` datetime DEFAULT NULL, `status` varchar[50] COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;6 được gửi
- Nhận ID kế hoạch đã chọn và thông tin người mua từ các trường biểu mẫu bằng phương thức PHP $_POST
- Tìm nạp chi tiết kế hoạch từ cơ sở dữ liệu dựa trên ID kế hoạch đã chọn
- Tạo khách hàng bằng phương pháp
CREATE TABLE `user_subscriptions` [ `id` int[11] NOT NULL AUTO_INCREMENT, `user_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "users" table', `plan_id` int[5] DEFAULT NULL COMMENT 'foreign key of "plans" table', `payment_method` enum['stripe'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'stripe', `stripe_subscription_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_customer_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_payment_intent_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `paid_amount` float[10,2] NOT NULL, `paid_amount_currency` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval_count` tinyint[2] NOT NULL DEFAULT 1, `customer_name` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `customer_email` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL, `plan_period_start` datetime DEFAULT NULL, `plan_period_end` datetime DEFAULT NULL, `status` varchar[50] COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
7 của Stripe Customer APICREATE TABLE `user_subscriptions` [ `id` int[11] NOT NULL AUTO_INCREMENT, `user_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "users" table', `plan_id` int[5] DEFAULT NULL COMMENT 'foreign key of "plans" table', `payment_method` enum['stripe'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'stripe', `stripe_subscription_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_customer_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_payment_intent_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `paid_amount` float[10,2] NOT NULL, `paid_amount_currency` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval_count` tinyint[2] NOT NULL DEFAULT 1, `customer_name` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `customer_email` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL, `plan_period_start` datetime DEFAULT NULL, `plan_period_end` datetime DEFAULT NULL, `status` varchar[50] COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
8 – Tên khách hàngCREATE TABLE `user_subscriptions` [ `id` int[11] NOT NULL AUTO_INCREMENT, `user_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "users" table', `plan_id` int[5] DEFAULT NULL COMMENT 'foreign key of "plans" table', `payment_method` enum['stripe'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'stripe', `stripe_subscription_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_customer_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_payment_intent_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `paid_amount` float[10,2] NOT NULL, `paid_amount_currency` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval_count` tinyint[2] NOT NULL DEFAULT 1, `customer_name` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `customer_email` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL, `plan_period_start` datetime DEFAULT NULL, `plan_period_end` datetime DEFAULT NULL, `status` varchar[50] COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
9 – Email khách hàng
- Tạo giá bằng phương pháp
CREATE TABLE `user_subscriptions` [ `id` int[11] NOT NULL AUTO_INCREMENT, `user_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "users" table', `plan_id` int[5] DEFAULT NULL COMMENT 'foreign key of "plans" table', `payment_method` enum['stripe'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'stripe', `stripe_subscription_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_customer_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_payment_intent_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `paid_amount` float[10,2] NOT NULL, `paid_amount_currency` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval_count` tinyint[2] NOT NULL DEFAULT 1, `customer_name` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `customer_email` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL, `plan_period_start` datetime DEFAULT NULL, `plan_period_end` datetime DEFAULT NULL, `status` varchar[50] COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
7 của Stripe Price APIINSERT INTO `plans` [`id`, `name`, `price`, `interval`] VALUES [1, 'Weekly Subscription', 25.00, 'week'], [2, 'Monthly Subscription', 75.00, 'month'], [3, 'Yearly Subscription', 799.00, 'year'];
1 – Một số nguyên dương tính bằng xu [hoặc 0 đối với gói miễn phí] sẽ tính phí định kỳINSERT INTO `plans` [`id`, `name`, `price`, `interval`] VALUES [1, 'Weekly Subscription', 25.00, 'week'], [2, 'Monthly Subscription', 75.00, 'month'], [3, 'Yearly Subscription', 799.00, 'year'];
2 – Mã tiền tệ ISO gồm ba chữ cái viết thườngINSERT INTO `plans` [`id`, `name`, `price`, `interval`] VALUES [1, 'Weekly Subscription', 25.00, 'week'], [2, 'Monthly Subscription', 75.00, 'month'], [3, 'Yearly Subscription', 799.00, 'year'];
3 – Chỉ định tần suất thanh toán [ngày, tuần, tháng hoặc năm]INSERT INTO `plans` [`id`, `name`, `price`, `interval`] VALUES [1, 'Weekly Subscription', 25.00, 'week'], [2, 'Monthly Subscription', 75.00, 'month'], [3, 'Yearly Subscription', 799.00, 'year'];
4 – Số khoảng thời gian giữa các lần thanh toán đăng ký. Ví dụ: interval=tháng và interval_count=2 hóa đơn cứ sau 2 tháng. Cho phép khoảng thời gian tối đa một năm [1 năm, 12 tháng hoặc 52 tuần]INSERT INTO `plans` [`id`, `name`, `price`, `interval`] VALUES [1, 'Weekly Subscription', 25.00, 'week'], [2, 'Monthly Subscription', 75.00, 'month'], [3, 'Yearly Subscription', 799.00, 'year'];
5 – Tên của gói thuê bao
- Tạo đăng ký bằng cách sử dụng phương pháp
CREATE TABLE `user_subscriptions` [ `id` int[11] NOT NULL AUTO_INCREMENT, `user_id` int[11] NOT NULL DEFAULT 0 COMMENT 'foreign key of "users" table', `plan_id` int[5] DEFAULT NULL COMMENT 'foreign key of "plans" table', `payment_method` enum['stripe'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'stripe', `stripe_subscription_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_customer_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `stripe_payment_intent_id` varchar[50] COLLATE utf8_unicode_ci NOT NULL, `paid_amount` float[10,2] NOT NULL, `paid_amount_currency` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval` varchar[10] COLLATE utf8_unicode_ci NOT NULL, `plan_interval_count` tinyint[2] NOT NULL DEFAULT 1, `customer_name` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `customer_email` varchar[50] COLLATE utf8_unicode_ci DEFAULT NULL, `created` datetime NOT NULL, `plan_period_start` datetime DEFAULT NULL, `plan_period_end` datetime DEFAULT NULL, `status` varchar[50] COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
7 của Stripe Subscription APIINSERT INTO `plans` [`id`, `name`, `price`, `interval`] VALUES [1, 'Weekly Subscription', 25.00, 'week'], [2, 'Monthly Subscription', 75.00, 'month'], [3, 'Yearly Subscription', 799.00, 'year'];
7 – Mã định danh của khách hàng đăng kýINSERT INTO `plans` [`id`, `name`, `price`, `interval`] VALUES [1, 'Weekly Subscription', 25.00, 'week'], [2, 'Monthly Subscription', 75.00, 'month'], [3, 'Yearly Subscription', 799.00, 'year'];
8 – ID của đối tượng giáINSERT INTO `plans` [`id`, `name`, `price`, `interval`] VALUES [1, 'Weekly Subscription', 25.00, 'week'], [2, 'Monthly Subscription', 75.00, 'month'], [3, 'Yearly Subscription', 799.00, 'year'];
9 – Tạo Đăng ký có trạng thái=chưa hoàn thành để thực hiện yêu cầu xác thực 3DS để hoàn tất thanh toán/* Stripe API configuration
0 – Sử dụng latest_invoice. thanh toán_intent
* Remember to switch to your live publishable and secret key in production!
* See your keys here: //dashboard.stripe.com/account/apikeys
*/
define['STRIPE_API_KEY', 'Your_API_Secret_key'];
define['STRIPE_PUBLISHABLE_KEY', 'Your_API_Publishable_key'];
define['STRIPE_CURRENCY', 'USD'];// Database configuration
define['DB_HOST', 'MySQL_Database_Host'];
define['DB_USERNAME', 'MySQL_Database_Username'];
define['DB_PASSWORD', 'MySQL_Database_Password'];
define['DB_NAME', 'MySQL_Database_Name'];
- Trả lại subscribeId, clientSecret và customerId về phía máy khách
Nếu
/* Stripe API configuration1 yêu cầu được gửi
* Remember to switch to your live publishable and secret key in production!
* See your keys here: //dashboard.stripe.com/account/apikeys
*/
define['STRIPE_API_KEY', 'Your_API_Secret_key'];
define['STRIPE_PUBLISHABLE_KEY', 'Your_API_Publishable_key'];
define['STRIPE_CURRENCY', 'USD'];// Database configuration
define['DB_HOST', 'MySQL_Database_Host'];
define['DB_USERNAME', 'MySQL_Database_Username'];
define['DB_PASSWORD', 'MySQL_Database_Password'];
define['DB_NAME', 'MySQL_Database_Name'];
- Nhận payment_intent, subscription_id và customer_id từ các trường biểu mẫu bằng phương thức PHP $_POST
- Tạo khách hàng bằng cách sử dụng phương thức tạo [] của Stripe Customer API
- Cập nhật Mục đích thanh toán với ID khách hàng bằng cách sử dụng phương thức update[] của API Mục đích thanh toán
- Truy xuất thông tin chi tiết về khách hàng bằng cách sử dụng phương thức lấy[] của Stripe Customer API
- Kiểm tra xem khoản phí có thành công hay không và xác thực trạng thái đăng ký
- Truy xuất thông tin chi tiết về khách hàng bằng cách sử dụng phương thức lấy[] của Stripe Customer API
- Nếu ID người dùng không có sẵn trong PHIÊN, hãy chèn chi tiết khách hàng vào bảng người dùng DB và lấy ID người dùng sẽ được liên kết với dữ liệu đăng ký
- Truy xuất chi tiết đăng ký bằng cách sử dụng phương thức lấy [] của API đăng ký Stripe
- Chèn dữ liệu giao dịch vào cơ sở dữ liệu bằng cách sử dụng Câu lệnh chuẩn bị sẵn của MySQL với PHP
- Trả lại ID chèn DB dưới dạng ID thanh toán cho phía máy khách
CREATE TABLE `plans` [ `id` int[11] NOT NULL AUTO_INCREMENT, `name` varchar[255] COLLATE utf8_unicode_ci NOT NULL, `price` float[10,2] NOT NULL DEFAULT 0.00 COMMENT 'Minimum amount is $0.50 US', `interval` enum['week','month','year'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'month', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;0
Trạng thái thanh toán [trạng thái thanh toán. php]
Dựa trên ý định thanh toán. trạng thái và xác nhận thanh toán bằng xác thực 3D Secure, người dùng được chuyển hướng đến trang này
- Lấy dữ liệu giao dịch từ cơ sở dữ liệu bằng PHP và MySQL
- Hiển thị trạng thái đăng ký và thông tin giao dịch trên trang web
CREATE TABLE `plans` [ `id` int[11] NOT NULL AUTO_INCREMENT, `name` varchar[255] COLLATE utf8_unicode_ci NOT NULL, `price` float[10,2] NOT NULL DEFAULT 0.00 COMMENT 'Minimum amount is $0.50 US', `interval` enum['week','month','year'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'month', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;1
Chi tiết thẻ kiểm tra
Để kiểm tra tích hợp API thanh toán đăng ký Stripe, hãy sử dụng các số thẻ kiểm tra sau, ngày hết hạn hợp lệ trong tương lai và bất kỳ số CVC ngẫu nhiên nào
- 4242424242424242 – Thị thực
- 4000056655665556 – Thị thực [ghi nợ]
- 5555555555554444 – Mastercard
- 5200828282828210 – Mastercard [ghi nợ]
- 378282246310005 – American Express
- 6011111111111117 – Khám phá
Kiểm tra số thẻ để xác thực an toàn 3D
- 4000002500003155 – Yêu cầu xác thực Bảo mật 3D [SCA]
- 4000002760003184 – Yêu cầu xác thực Bảo mật 3D [SCA]
Làm cho cổng thanh toán Stripe hoạt động
Sau khi quá trình tích hợp API đăng ký hoàn tất và quy trình thanh toán hoạt động bình thường, hãy làm theo các bước bên dưới để làm cho cổng thanh toán Stripe hoạt động
- Đăng nhập vào tài khoản Stripe của bạn và điều hướng đến trang Nhà phát triển » Khóa API
- Thu thập các khóa API [Khóa có thể xuất bản và Khóa bí mật] từ phần DỮ LIỆU TRỰC TIẾP
- Trong tệp
CREATE TABLE `plans` [ `id` int[11] NOT NULL AUTO_INCREMENT, `name` varchar[255] COLLATE utf8_unicode_ci NOT NULL, `price` float[10,2] NOT NULL DEFAULT 0.00 COMMENT 'Minimum amount is $0.50 US', `interval` enum['week','month','year'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'month', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
7, thay thế các khóa API thử nghiệm [Khóa có thể xuất bản và Khóa bí mật] bằng các khóa API trực tiếp [Khóa có thể xuất bản và Khóa bí mật].CREATE TABLE `plans` [ `id` int[11] NOT NULL AUTO_INCREMENT, `name` varchar[255] COLLATE utf8_unicode_ci NOT NULL, `price` float[10,2] NOT NULL DEFAULT 0.00 COMMENT 'Minimum amount is $0.50 US', `interval` enum['week','month','year'] COLLATE utf8_unicode_ci NOT NULL DEFAULT 'month', PRIMARY KEY [`id`] ] ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
2
Đăng ký PayPal Tích hợp cổng thanh toán trong PHP
Phần kết luận
API thanh toán đăng ký sọc là tùy chọn dễ dàng nhất để chấp nhận thanh toán tín dụng trực tuyến cho đăng ký. Bạn có thể thêm tính năng thanh toán định kỳ vào ứng dụng web bằng API Stripe và PHP. Tập lệnh ví dụ của chúng tôi giúp bạn tính phí người dùng định kỳ trong một khoảng thời gian cụ thể thông qua Stripe. Ngoài ra, tính năng xác thực Bảo mật 3D được tích hợp để làm cho tập lệnh tích hợp Stripe này sẵn sàng cho SCA [Xác thực khách hàng mạnh mẽ]. Chức năng của tập lệnh thanh toán đăng ký Stripe này có thể được nâng cao theo nhu cầu của bạn
Bạn có muốn nhận trợ giúp triển khai hay sửa đổi hoặc nâng cao chức năng của tập lệnh này không?