laravel-pagseguro ใช้ PagSeguro API และมอบวิธีง่ายๆ ในการสร้างการชำระเงินและแจ้งเตือนเกี่ยวกับธุรกรรมของคุณ
ก่อนที่คุณจะใช้ laravel pagseguro สิ่งสำคัญคือต้องตรวจสอบว่าชื่อผู้ใช้ PagSeguro ของคุณถูกต้องสำหรับการรวมระบบ ปฏิบัติตาม URL การกำหนดค่าผู้ใช้ PagSeguro: https://pagseguro.uol.com.br/preferencias/integracoes.jhtml
PHP >= 5.4 Laravel 5.x
เปิดไฟล์ composer.json
และป้อนคำสั่งต่อไปนี้:
"require": {
"michael/laravelpagseguro": "dev-master"
}
หมายเหตุ : สำหรับ laravel เวอร์ชัน 5.1 หรือต่ำกว่า ให้ระบุเวอร์ชัน 0.4.1 แทนการใช้ dev-master
หลังจากแทรก laravel pagseguro
ลงใน need แล้ว คุณต้องดำเนินการคำสั่ง:
composer update
หรือรันคำสั่ง:
composer require michael/laravelpagseguro:dev-master
เปิดไฟล์ config/app.php
และเพิ่มคำสั่งต่อไปนี้ลงในอาร์เรย์ providers
:
laravel pagseguro Platform Laravel5 ServiceProvider::class
ในไฟล์ config/app.php
ให้เพิ่มคำสั่งต่อไปนี้ลงในอาร์เรย์ aliases
:
' PagSeguro ' => laravel pagseguro Platform Laravel5 PagSeguro::class
ตอนนี้คุณจะรันคำสั่ง:
php artisan vendor:publish
หากทุกอย่างเป็นไปด้วยดี ข้อความต่อไปนี้จะปรากฏขึ้น:
Copied File [/vendor/michael/laravelpagseguro/src/laravel/pagseguro/Config/laravelpagseguro.php] To [/config/laravelpagseguro.php]
เปิดไฟล์ config/laravelpagseguro.php
และเปลี่ยน token
และ e-mail
แจ้งร้านค้าของคุณ:
' credentials ' => array ( //SETA AS CREDENCIAIS DE SUA LOJA
' token ' => null ,
' email ' => null ,
)
หากคุณต้องการพร็อกซีเพื่อใช้ laravel pagseguro ยกเลิกการใส่เครื่องหมายข้อคิดเห็นและกำหนดค่าบรรทัดอะแดปเตอร์ http:
' http ' => [
' adapter ' => [
' type ' => ' curl ' ,
' options ' => [
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0 ,
// CURLOPT_PROXY => 'http://user:pass@host:port', // PROXY OPTION <<--
]
],
],
อาร์เรย์การส่งจะต้องประกอบขึ้นด้วยโครงสร้างดังต่อไปนี้:
$ data = [
' items ' => [
[
' id ' => ' 18 ' ,
' description ' => ' Item Um ' ,
' quantity ' => ' 1 ' ,
' amount ' => ' 1.15 ' ,
' weight ' => ' 45 ' ,
' shippingCost ' => ' 3.5 ' ,
' width ' => ' 50 ' ,
' height ' => ' 45 ' ,
' length ' => ' 60 ' ,
],
[
' id ' => ' 19 ' ,
' description ' => ' Item Dois ' ,
' quantity ' => ' 1 ' ,
' amount ' => ' 3.15 ' ,
' weight ' => ' 50 ' ,
' shippingCost ' => ' 8.5 ' ,
' width ' => ' 40 ' ,
' height ' => ' 50 ' ,
' length ' => ' 80 ' ,
],
],
' shipping ' => [
' address ' => [
' postalCode ' => ' 06410030 ' ,
' street ' => ' Rua Leonardo Arruda ' ,
' number ' => ' 12 ' ,
' district ' => ' Jardim dos Camargos ' ,
' city ' => ' Barueri ' ,
' state ' => ' SP ' ,
' country ' => ' BRA ' ,
],
' type ' => 2 ,
' cost ' => 30.4 ,
],
' sender ' => [
' email ' => ' [email protected] ' ,
' name ' => ' Isaque de Souza Barbosa ' ,
' documents ' => [
[
' number ' => ' 01234567890 ' ,
' type ' => ' CPF '
]
],
' phone ' => [
' number ' => ' 985445522 ' ,
' areaCode ' => ' 11 ' ,
],
' bornDate ' => ' 1988-03-21 ' ,
]
];
เมื่อคุณมีข้อมูลแล้ว ให้ใช้วิธีการ: createFromArray
เพื่อสร้างออบเจ็กต์การชำระเงิน:
$ checkout = PagSeguro:: checkout ()-> createFromArray ( $ data );
เพื่อยืนยันการส่งให้ใช้วิธีการ: send
ดังต่อไปนี้:
$ checkout = PagSeguro:: checkout ()-> createFromArray ( $ data );
$ credentials = PagSeguro:: credentials ()-> get ();
$ information = $ checkout -> send ( $ credentials ); // Retorna um objeto de laravelpagseguroCheckoutInformationInformation
if ( $ information ) {
print_r ( $ information -> getCode ());
print_r ( $ information -> getDate ());
print_r ( $ information -> getLink ());
}
การรายงานข้อมูลเมตาการเติมเงินโทรศัพท์มือถือ:
// ....
$ data [ ' cellphone_charger ' ] = ' +5511980810000 ' ;
$ checkout = PagSeguro:: checkout ()-> createFromArray ( $ data );
การรายงานข้อมูลเมตาสำหรับข้อมูลการเดินทาง:
// ....
$ data [ ' travel ' ] = [
' passengers ' => [
[
' name ' => ' Isaque de Souza ' ,
' cpf ' => ' 40404040411 ' ,
' passport ' => ' 4564897987 '
],
[
' name ' => ' Michael Douglas ' ,
' cpf ' => ' 80808080822 ' ,
]
],
' origin ' => [
' city ' => ' SAO PAULO - SP ' ,
' airportCode ' => ' CGH ' , // Congonhas
],
' destination ' => [
' city ' => ' RIO DE JANEIRO - RJ ' ,
' airportCode ' => ' SDU ' , // Santos Dumont
]
];
$ checkout = PagSeguro:: checkout ()-> createFromArray ( $ data );
การรายงานข้อมูลเมตาสำหรับเกม:
// ....
$ data [ ' game ' ] = [
' gameName ' => ' PS LEGEND ' ,
' playerId ' => ' BR561546S4 ' ,
' timeInGameDays ' => 360 ,
];
$ checkout = PagSeguro:: checkout ()-> createFromArray ( $ data );
หากต้องการดึงข้อมูลรับรองเริ่มต้นจากไฟล์คุณสามารถใช้:
$ credentials = PagSeguro:: credentials ()-> get ();
หรือใช้ข้อมูลรับรองอื่น
$ credentials = PagSeguro:: credentials ()-> create ( $ token , $ email );
$ credentials = PagSeguro:: credentials ()-> get ();
$ transaction = PagSeguro:: transaction ()-> get ( $ code , $ credentials );
$ information = $ transaction -> getInformation ();
สร้างเส้นทาง POST ด้วยชื่อ "pagseguro.notification" (ซึ่งอยู่ในการกำหนดค่า)
Route:: post ( ' /pagseguro/notification ' , [
' uses ' => ' laravelpagseguroPlatformLaravel5NotificationController@notification ' ,
' as ' => ' pagseguro.notification ' ,
]);
ลงทะเบียนการโทรกลับ (โทรได้) ในการกำหนดค่า laravelpagseguro.php ของคุณ
' routes ' => [
' notification ' => [
' callback ' => [ ' MyNotificationClass ' , ' myMethod ' ], // Callable
' credential ' => ' default ' ,
' route-name ' => ' pagseguro.notification ' , // Nome da rota
],
],
หรือ....
' routes ' => [
' notification ' => [
' callback ' => function ( $ information ) { // Callable
Log:: debug ( print_r ( $ information , 1 ));
},
],
],
ในไฟล์กำหนดค่าคุณควรปล่อยไว้ดังนี้:
' notification ' => [
' callback ' => [ ' AppControllersPagSeguroController ' , ' Notification ' ], // Callable callback to Notification function (notificationInfo) : void {}
' credential ' => ' default ' , // Callable resolve credential function (notificationCode) : Credentials {}
' route-name ' => ' pagseguro.notification ' , // Criar uma rota com este nome
],
และในคอนโทรลเลอร์ คุณต้องสร้างวิธีการ เช่น การแจ้งเตือน:
public static function Notification ( $ information )
{
Log:: debug ( print_r ( $ information -> getStatus ()-> getCode (), 1 ));
}
การสร้างแผนการชำระเงินแบบประจำเริ่มต้นด้วยการสร้างแผน และในการดำเนินการนี้ คุณต้องสร้างอาร์เรย์ต่อไปนี้:
หากคุณต้องการดูวัตถุคำขอ: https://dev.pagseguro.uol.com.br/v1.0/reference#criar-plano
$ plan = [
' body ' => [
' reference ' => ' plano laravel pagseguro ' ,
],
' preApproval ' => [
' name ' => ' Plano ouro - mensal ' ,
' charge ' => ' AUTO ' , // outro valor pode ser MANUAL
' period ' => ' MONTHLY ' , //WEEKLY, BIMONTHLY, TRIMONTHLY, SEMIANNUALLY, YEARLY
' amountPerPayment ' => ' 125.00 ' , // obrigatório para o charge AUTO - mais que 1.00, menos que 2000.00
' membershipFee ' => ' 50.00 ' , //opcional - cobrado com primeira parcela
' trialPeriodDuration ' => 30 , //opcional
' details ' => ' Decrição do plano ' , //opcional
' expiration ' => [ // opcional
' value ' => 1 , // obrigatório de 1 a 1000000
' unit ' => ' YEARLY ' , // obrigatório
],
]
];
จากนั้นคุณต้องเรียกวิธีการสร้างแผน:
$ plan = PagSeguro:: plan ()-> createFromArray ( $ plan );
$ credentials = PagSeguro:: credentials ()-> get ();
$ information = $ plan -> send ( $ credentials ); // Retorna um objeto de laravelpagseguroCheckoutInformationInformation
if ( $ information ) {
print_r ( $ information -> getCode ());
print_r ( $ information -> getDate ());
print_r ( $ information -> getLink ());
}
laravel pagseguro ใช้ใบอนุญาต MIT เพื่อดูข้อมูลเพิ่มเติมอ่านลิงก์: ใบอนุญาต MIT