laravel pagseguro -1.0.6
Laravel-Pagseguro消耗了Pagseguro API,并证明了一种简单的付款方式,并通知您的交易。
用户创建和配置
在使用laravel pagseguro之前
兼容性
php> = 5.4 laravel 5.x
安装
打开composer.json文件并输入以下指令:
\"require\": {
\"michael/laravelpagseguro\": \"dev-master\"
}
注意:对于Laravel的5.1版或以下版本,指定版本0.4.1而不是使用Dev-Master
将laravel pagseguro插入精炼之后,您应该执行命令:
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 \' => \' sender@gmail.com \' , \' 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 laravel\\pagseguro\\Checkout\\Information\\Information 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”(在config)的邮局
Route:: post ( \' /pagseguro/notification \' , [ \' uses \' => \' \\laravel\\pagseguro\\Platform\\Laravel5\\NotificationController@notification \' , \' as \' => \' pagseguro.notification \' , ]);
在您的config 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 \' => [ \' App\\Controllers\\PagSeguroController \' , \' 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-plan
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 = [ \' 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 laravel\\pagseguro\\Checkout\\Information\\Information if ( $ information ) { print_r ( $ information -> getCode ()); print_r ( $ information -> getDate ()); print_r ( $ information -> getLink ()); }
执照
laravel pagseguro使用MIT许可证,以了解更多阅读链接:MIT许可证
