somosgad / laravel-payu
A Laravel package to encapsulate global PayU requests
dev-master
2020-02-03 20:51 UTC
Requires
- guzzlehttp/guzzle: ^6.3 <=6.5.0
- illuminate/support: ^6.0
- webmozart/assert: ^1.6
Requires (Dev)
- mockery/mockery: ^1.3
- orchestra/testbench: ^4.0
- phpunit/phpunit: ^8.5
- sempro/phpunit-pretty-print: ^1.2
- vlucas/phpdotenv: ^3.3
This package is auto-updated.
Last update: 2025-03-29 01:01:16 UTC
README
A Laravel package to encapsulate global PayU requests. More info at PaymentsOS Docs.
Currently in development
Installation
Via Composer
composer require somosgad/laravel-payu:dev-master
Configuration
Set API variables
Set your PayU configs at .env
file
PAYU_APP_ID= PAYU_ENV= PAYU_PUBLIC_KEY= PAYU_PRIVATE_KEY= PAYU_PROVIDER=
Your .env
file must end up looking like:
PAYU_APP_ID=com.foo.bar PAYU_ENV=test PAYU_PUBLIC_KEY=g6l2g4yn-nvgp-uiil-6fm7-d2337cegunmz PAYU_PRIVATE_KEY=68lhkww3-lkgw-4mcc-r21m-cf8nnnx3wj2k PAYU_PROVIDER="PayU Argentina"
Export Config
php artisan vendor:publish --provider="SomosGAD_\LaravelPayU\LaravelPayUServiceProvider"
Usage
use SomosGAD_\LaravelPayU\LaravelPayU; $payu = new LaravelPayU;
Payment
Create
$amount = 2000; $currency = 'USD'; $payment = $payu->createPayment($amount, $currency);
Create Token
$card_number = '4111111111111111'; $credit_card_cvv = '123'; $expiration_date = '10/29'; $holder_name = 'John Doe'; $token_type = 'credit_card'; $token = $payu->createToken( $card_number, $credit_card_cvv, $expiration_date, $holder_name, $token_type );
Create Authorization
$authorization = $payu->createAuthorization($payment['id'], $encrypted_cvv, $token);
Create Capture
$capture = $payu->createCapture($payment['id'], $payment['amount']);
Charge
Create Card Charge
$charge = $payu->createCharge($payment['id'], $token);
Create Cash Charge
$charge = $payu->createCharge2($payment['id'], [ 'payment_method' => [ 'source_type' => 'cash', 'type' => 'untokenized', 'vendor' => 'COBRO_EXPRESS', 'additional_details' => [ 'order_language' => 'en', 'cash_payment_method_vendor' => 'COBRO_EXPRESS', 'payment_method' => 'PSE', 'payment_country' => 'ARG', ], ], 'reconciliation_id' => time(), ];
* Notes:
order_language
is always uppercased for you;- Omitted
reconciliation_id
gets created; - Only
ARG
payment_country
are able to create cash charges for Argentina; - Payments for cash charges must be created with
customer_id
set and customer must haveshipping_address
set with at least one field, otherwise, the receipt won't be printable or downloadable.
Customer
Create Customer
Required Props
$customer = $payu->createCustomer([ 'customer_reference' => 'johntravolta18021954', ]);
* Notes:
customer_reference
s are unique, API won't create customers for same references. Choose something like an ID, document or anything else unique and immutable to set ascustomer_reference
.- PayU Argentina won't print or download PDF if you haven't set customer's
shipping_address
with at least one info (likecountry
or any other field).
Customer Sample from PayU API Docs
$customer = $payu->createCustomer([ 'customer_reference' => 'johntravolta18021954', 'email' => 'john@travolta.com', ]);
Optional Props
$customer = $payu->createCustomer([ 'customer_reference' => 'johntravolta18021954', 'email' => 'john@travolta.com', 'first_name' => 'John', 'last_name' => 'Travolta', 'additional_details' => [ 'extra1' => 'Info Extra 1', 'extra2' => 'Info Extra 2', ], 'shipping_address' => [ 'country' => 'ARG', 'state' => 'TX', 'city' => 'Customer Shipping City', 'line1' => '10705 Old Mill Rd', 'line2' => '10706 Young Mill Rd', 'zip_code' => '75402-3435', 'title' => 'Dr.', 'first_name' => 'John', 'last_name' => 'Travolta', 'phone' => '23645963', 'email' => 'john@travolta.com', ], ]);
Delete Customer
$customer_id = '0ab5511c-3a62-4b4b-8682-cb3c15172965'; $delete = $payu->deleteCustomer($customer_id);
Get Customer by ID
$customer_id = '0ab5511c-3a62-4b4b-8682-cb3c15172965'; $customer = $payu->getCustomerById($customer_id);
Get Customers by Reference
$customer_reference = 'johntravolta18021954'; $customers = $payu->getCustomerByReference($customer_reference);
* Note: getCustomerByReference
returns an array
not a single record like getCustomerById
;
Create Payment Method
$payment_method = $payu->createPaymentMethod($customer['id'], $token);
Testing
phpunit
Contributing
Feel free to contribute with anything on this package or contact us about it.
Security
If you discover any security related issues, please email giovanni@somosgad.com instead of using the issue tracker.
Credits
License
MIT. Please see the license file for more information.