laravel-pagseguro는 PagSeguro API를 사용하여 결제를 생성하고 거래에 대해 알리는 간단한 방법을 제공합니다.
laravel pagseguro 사용하기 전에 PagSeguro 사용자 이름이 통합에 적합한지 확인하는 것이 중요합니다. PagSeguro 사용자 구성 URL: https://pagseguro.uol.com.br/preferencias/integracoes.jhtml을 따르세요.
PHP >= 5.4 라라벨 5.x
composer.json
파일을 열고 다음 명령문을 입력하십시오.
"require": {
"michael/laravelpagseguro": "dev-master"
}
참고 : laravel 버전 5.1 이하의 경우 dev-master를 사용하는 대신 버전 0.4.1을 지정하세요.
laravel pagseguro
require에 삽입한 후 다음 명령을 실행해야 합니다.
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 ();
"pagseguro.notification"이라는 이름으로 POST 경로를 만듭니다(구성에 있음).
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 라이센스 링크를 참조하세요.