paymob / php-library
Paymob PHP 库
1.0.3
2024-06-03 12:26 UTC
Requires
- php: >=7
- ext-curl: *
README
Paymob PHP 库将 Paymob 快捷支付集成到 PHP 平台上。
安装
您可以通过 Composer 需求它
composer require paymob/php-library
用法
配置数组
$paymobKeys['apiKey'] = '';
$paymobKeys['pubKey'] = '';
$paymobKeys['secKey'] = '';
获取 HMAC 和可用的集成 ID
$paymobReq = new Paymob();
$result = $paymobReq->authToken($paymobKeys);
echo "<pre>";
print_r($result);
使用 Paymob 创建一个意向
$cents = 100; // 100 for all countries and 1000 for Oman
$billing = [
"email" => 'email@email.com',
"first_name" => 'fname',
"last_name" => 'lname',
"street" => 'street',
"phone_number" => '1234567890',
"city" => 'city',
"country" => 'country',
"state" => 'state',
"postal_code" => '12345',
];
$data = [
"amount" => 10 * $cents,
"currency" => 'EGP',
"payment_methods" => array(1234567), // replace this id 1234567 with your integration ID(s)
"billing_data" => $billing,
"extras" => ["merchant_intention_id" => '123_' . time()],
"special_reference" => '123_' . time()
];
$status = $paymobReq->createIntention($paymobKeys['secKey'], $data);
echo "<pre/>";
print_r($status);
获取 Paymob 快捷支付 URL
$countryCode = $paymobReq->getCountryCode($paymobKeys['secKey']);
$apiUrl = $paymobReq->getApiUrl($countryCode);
$cs = $status['cs'];
$to = $apiUrl . "unifiedcheckout/?publicKey=" . $paymobKeys['pubKey'] . "&clientSecret=$cs";
echo "Pay using the URL $to";