PHPackages                             phuongnamsoft/omnipay-vnpay - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. phuongnamsoft/omnipay-vnpay

ActiveLibrary[Payment Processing](/categories/payments)

phuongnamsoft/omnipay-vnpay
===========================

Library supports integrating VNPay payment gateway.

v1.0.0(1y ago)03MITPHPPHP ^7.4|^8

Since Oct 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/phuongnamsoft/omnipay-vnpay)[ Packagist](https://packagist.org/packages/phuongnamsoft/omnipay-vnpay)[ Docs](https://github.com/phuongnamsoft/omnipay-vnpay)[ RSS](/packages/phuongnamsoft-omnipay-vnpay/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

Thông tin
---------

[](#thông-tin)

Thư viện hổ trợ tích cổng thanh toán VNPay phát triển trên nền tảng [Omnipay League](https://github.com/thephpleague/omnipay).

Để nắm sơ lược về khái niệm và cách sử dụng các **Omnipay** gateways bạn hãy truy cập vào [đây](https://omnipay.thephpleague.com/)để kham khảo.

Cài đặt
-------

[](#cài-đặt)

Cài đặt Omnipay VNPay thông qua [Composer](https://getcomposer.org):

```
composer require phuongnamsoft/omnipay-vnpay
```

Cách sử dụng
------------

[](#cách-sử-dụng)

hoặc nếu bạn muốn sử dụng không dựa trên framework thì tiếp tục xem tiếp.

### Khởi tạo gateway:

[](#khởi-tạo-gateway)

```
use Omnipay\Omnipay;

$gateway = Omnipay::create('VNPay');
$gateway->initialize([
    'vnp_TmnCode' => 'Do VNPay cấp',
    'vnp_HashSecret' => 'Do VNPay cấp',
]);
```

Gateway khởi tạo ở trên dùng để tạo các yêu cầu xử lý đến VNPay hoặc dùng để nhận yêu cầu do VNPay gửi đến.

### Tạo yêu cầu thanh toán:

[](#tạo-yêu-cầu-thanh-toán)

```
$response = $gateway->purchase([
    'vnp_TxnRef' => time(),
    'vnp_OrderType' => 100000,
    'vnp_OrderInfo' => time(),
    'vnp_IpAddr' => '127.0.0.1',
    'vnp_Amount' => 1000000,
    'vnp_ReturnUrl' => 'https://github.com/phuongnamsoft',
])->send();

if ($response->isRedirect()) {
    $redirectUrl = $response->getRedirectUrl();

    // TODO: chuyển khách sang trang VNPay để thanh toán
}
```

Kham khảo thêm các tham trị khi tạo yêu cầu và VNPay trả về tại [đây](https://sandbox.vnpayment.vn/apis/docs/huong-dan-tich-hop/#t%E1%BA%A1o-url-thanh-to%C3%A1n).

### Kiểm tra thông tin `vnp_ReturnUrl` khi khách được VNPay redirect về:

[](#kiểm-tra-thông-tin-vnp_returnurl-khi-khách-được-vnpay-redirect-về)

```
$response = $gateway->completePurchase()->send();

if ($response->isSuccessful()) {
    // TODO: xử lý kết quả và hiển thị.
    print $response->vnp_Amount;
    print $response->vnp_TxnRef;

    var_dump($response->getData()); // toàn bộ data do VNPay gửi sang.

} else {

    print $response->getMessage();
}
```

Kham khảo thêm các tham trị khi VNPay trả về tại [đây](https://sandbox.vnpayment.vn/apis/docs/huong-dan-tich-hop/#code-returnurl).

### Kiểm tra thông tin `IPN` do VNPay gửi sang:

[](#kiểm-tra-thông-tin-ipn-do-vnpay-gửi-sang)

```
$response = $gateway->notification()->send();

if ($response->isSuccessful()) {
    // TODO: xử lý kết quả.
    print $response->vnp_Amount;
    print $response->vnp_TxnRef;

    var_dump($response->getData()); // toàn bộ data do VNPay gửi sang.

} else {

    print $response->getMessage();
}
```

Kham khảo thêm các tham trị khi VNPay gửi sang tại [đây](https://sandbox.vnpayment.vn/apis/docs/huong-dan-tich-hop/#code-ipn-url).

### Kiểm tra trạng thái giao dịch:

[](#kiểm-tra-trạng-thái-giao-dịch)

```
$response = $gateway->queryTransaction([
    'vnp_TransDate' => 20190705151126,
    'vnp_TxnRef' => 1562314234,
    'vnp_OrderInfo' => time(),
    'vnp_IpAddr' => '127.0.0.1',
    'vnp_TransactionNo' => 496558,
])->send();

if ($response->isSuccessful()) {
    // TODO: xử lý kết quả và hiển thị.
    print $response->getTransactionId();
    print $response->getTransactionReference();

    var_dump($response->getData()); // toàn bộ data do VNPay gửi về.

} else {

    print $response->getMessage();
}
```

Kham khảo thêm các tham trị khi tạo yêu cầu và VNPay trả về tại [đây](https://goo.gl/FHdM5B).

### Yêu cầu hoàn tiền:

[](#yêu-cầu-hoàn-tiền)

```
$response = $gateway->refund([
    'vnp_Amount' => 10000,
    'vnp_TransactionType' => '03',
    'vnp_TransDate' => 20190705151126,
    'vnp_TxnRef' => 32321,
    'vnp_OrderInfo' => time(),
    'vnp_IpAddr' => '127.0.0.1',
    'vnp_TransactionNo' => 496558,
])->send();

if ($response->isSuccessful()) {
    // TODO: xử lý kết quả và hiển thị.
    print $response->getTransactionId();
    print $response->getTransactionReference();

    var_dump($response->getData()); // toàn bộ data do VNPay gửi về.

} else {

    print $response->getMessage();
}
```

Kham khảo thêm các tham trị khi tạo yêu cầu và VNPay trả về tại [đây](https://goo.gl/FHdM5B).

Dành cho nhà phát triển
-----------------------

[](#dành-cho-nhà-phát-triển)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

585d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bca7b7f1436b5da8de0666fe6150c61704e07c73d25322f1eeeacd2778dc9823?d=identicon)[pns](/maintainers/pns)

---

Top Contributors

[![phuongnamsoft](https://avatars.githubusercontent.com/u/4836324?v=4)](https://github.com/phuongnamsoft "phuongnamsoft (2 commits)")

---

Tags

paymentpayment gatewayvietnam-paymentvietnam-payment-gatewayvnpay

### Embed Badge

![Health badge](/badges/phuongnamsoft-omnipay-vnpay/health.svg)

```
[![Health](https://phpackages.com/badges/phuongnamsoft-omnipay-vnpay/health.svg)](https://phpackages.com/packages/phuongnamsoft-omnipay-vnpay)
```

###  Alternatives

[phpviet/omnipay-vnpay

Thư viện hổ trợ tích hợp cổng thanh toán VNPay.

178.2k2](/packages/phpviet-omnipay-vnpay)[shetabit/payment

Laravel Payment Gateway Integration Package

944330.1k5](/packages/shetabit-payment)[phpviet/omnipay-momo

Thư viện hổ trợ tích hợp cổng thanh toán MoMo.

318.3k2](/packages/phpviet-omnipay-momo)[shetabit/multipay

PHP Payment Gateway Integration Package

291348.2k3](/packages/shetabit-multipay)[cybersource/rest-client-php

Client SDK for CyberSource REST APIs

39881.3k6](/packages/cybersource-rest-client-php)[tzsk/payu

PayU India Payment Gateway Integration with Laravel

47108.8k6](/packages/tzsk-payu)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
