PHPackages                             kientv/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. kientv/omnipay-vnpay

ActiveLibrary[Payment Processing](/categories/payments)

kientv/omnipay-vnpay
====================

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

1.0.2(5y ago)0110MITPHPPHP ^7.1

Since Jul 5Pushed 4y agoCompare

[ Source](https://github.com/kientv/omnipay-vnpay)[ Packagist](https://packagist.org/packages/kientv/omnipay-vnpay)[ Docs](https://github.com/phpviet/omnipay-vnpay)[ RSS](/packages/kientv-omnipay-vnpay/feed)WikiDiscussions master Synced yesterday

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

 [ ![](https://raw.githubusercontent.com/kientv/omnipay-vnpay/master/resources/logo.png) ](https://vnpay.vn)

Omnipay: VNPay
==============

[](#omnipay-vnpay)

 [![Latest version](https://camo.githubusercontent.com/916fcb59b1f3c40894df7ac24f0fb7fd210a2951fc306b733cb0c6daa0fe750c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b69656e74762f6f6d6e697061792d766e7061792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kientv/omnipay-vnpay) [![Total download](https://camo.githubusercontent.com/ce0591ce83692a0dbbf95b3b632c492ce192437ede9ae55bb4d438dac478e0ae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b69656e74762f6f6d6e697061792d766e7061792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kientv/omnipay-vnpay) [![License](https://camo.githubusercontent.com/eed1b94a16f063c982411b78472179c5c7e4c2e5ecd6fdf0df31257f12221e4b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b69656e74762f6f6d6e697061792d766e7061792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kientv/omnipay-vnpay)

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 kientv/omnipay-vnpay
```

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

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

### Tích hợp sẵn trên các framework phổ biến hiện tại

[](#tích-hợp-sẵn-trên-các-framework-phổ-biến-hiện-tại)

- [`Laravel`](https://github.com/phpviet/laravel-omnipay)
- [`Symfony`](https://github.com/phpviet/symfony-omnipay)
- [`Yii`](https://github.com/phpviet/yii-omnipay)

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/phpviet',
])->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)

Nếu như bạn cảm thấy thư viện chúng tôi còn thiếu sót hoặc sai sót và bạn muốn đóng góp để phát triển chung, chúng tôi rất hoan nghênh! Hãy tạo các `issue` để đóng góp ý tưởng cho phiên bản kế tiếp hoặc tạo `PR`để đóng góp phần thiếu sót hoặc sai sót. Riêng đối với các lỗi liên quan đến bảo mật thì phiền bạn gửi email đến  thay vì tạo issue. Cảm ơn!

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.9% 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

Every ~185 days

Total

3

Last Release

2132d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ea322040daf363c6f00b70e35c1f134c703eb2e33a71c65950db952ff3a8c96?d=identicon)[kientv](/maintainers/kientv)

---

Top Contributors

[![vuongxuongminh](https://avatars.githubusercontent.com/u/38932626?v=4)](https://github.com/vuongxuongminh "vuongxuongminh (24 commits)")[![vanthao03596](https://avatars.githubusercontent.com/u/34786441?v=4)](https://github.com/vanthao03596 "vanthao03596 (2 commits)")[![kientv](https://avatars.githubusercontent.com/u/3217438?v=4)](https://github.com/kientv "kientv (1 commits)")

---

Tags

paymentpayment gatewayphpvietvietnam-paymentvietnam-payment-gatewayvnpay

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/kientv-omnipay-vnpay/health.svg)](https://phpackages.com/packages/kientv-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)[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/payment

Laravel Payment Gateway Integration Package

944330.1k5](/packages/shetabit-payment)[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)
