Skip to content

Commit b039e36

Browse files
Merge remote-tracking branch 'origin/develop'
2 parents 8fbedfa + b8fb307 commit b039e36

20 files changed

+168
-87
lines changed

README.md

Lines changed: 91 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,127 @@
11

2-
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/support-ukraine.svg?t=1" />](https://supportukrainenow.org)
3-
4-
# Implementation of viva wallet's API for laravel projects
2+
# Viva Wallet's API for Laravel applications
53

4+
![PHP Version](https://img.shields.io/packagist/php-v/deyjandi/laravel-viva-wallet)
5+
![Laravel Version](https://img.shields.io/badge/laravel-%3E%3D8-red)
66
[![Latest Version on Packagist](https://img.shields.io/packagist/v/deyjandi/laravel-viva-wallet.svg?style=flat-square)](https://packagist.org/packages/deyjandi/laravel-viva-wallet)
77
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/deyjandi/laravel-viva-wallet/run-tests?label=tests)](https://github.com/deyjandi/laravel-viva-wallet/actions?query=workflow%3Arun-tests+branch%3Amain)
88
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/deyjandi/laravel-viva-wallet/Check%20&%20fix%20styling?label=code%20style)](https://github.com/deyjandi/laravel-viva-wallet/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
99
[![Total Downloads](https://img.shields.io/packagist/dt/deyjandi/laravel-viva-wallet.svg?style=flat-square)](https://packagist.org/packages/deyjandi/laravel-viva-wallet)
1010

1111
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
1212

13-
## Support us
14-
15-
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-viva-wallet.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-viva-wallet)
16-
17-
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
18-
19-
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
2013

21-
## Installation
14+
## Installation steps
2215

23-
You can install the package via composer:
16+
### 1. install the package via composer:
2417

2518
```bash
2619
composer require deyjandi/laravel-viva-wallet
2720
```
2821

29-
You can publish and run the migrations with:
22+
### 2. Publish the `config` file with:
3023

3124
```bash
32-
php artisan vendor:publish --tag="laravel-viva-wallet-migrations"
33-
php artisan migrate
25+
php artisan vendor:publish --tag="viva-wallet-config"
3426
```
3527

36-
You can publish the config file with:
37-
28+
### 3. Add at minimum the following to the `.env` file
3829
```bash
39-
php artisan vendor:publish --tag="laravel-viva-wallet-config"
30+
VIVA_WALLET_MERCHANT_ID=<your-merchant-id>
31+
VIVA_WALLET_API_KEY=<your-api-id>
32+
VIVA_WALLET_CLIENT_ID=<your-smart-checkout-client-id>
33+
VIVA_WALLET_CLIENT_SECRET=<your-smart-checkout-secret>
4034
```
35+
You can refer to the `./config/viva-wallet-config.php` for additional configuration options
36+
37+
## Usage
4138

42-
This is the contents of the published config file:
39+
40+
### Create a Payment Order using the default configuration:
4341

4442
```php
45-
return [
46-
];
43+
...
44+
45+
use Deyjandi\VivaWallet\Facades\VivaWallet;
46+
use Deyjandi\VivaWallet\Payment;
47+
48+
...
49+
50+
$payment = new Payment($amount = 1000);
51+
52+
$checkoutUrl = VivaWallet::createPaymentOrder($payment);
53+
54+
...
4755
```
4856

49-
Optionally, you can publish the views using
57+
### Create a Payment Order specifying every configurable option:
5058

51-
```bash
52-
php artisan vendor:publish --tag="laravel-viva-wallet-views"
59+
```php
60+
...
61+
62+
use Deyjandi\VivaWallet\Enums\RequestLang;
63+
use Deyjandi\VivaWallet\Enums\PaymentMethod;
64+
use Deyjandi\VivaWallet\Facades\VivaWallet;
65+
use Deyjandi\VivaWallet\Customer;
66+
use Deyjandi\VivaWallet\Payment;
67+
68+
...
69+
70+
$customer = new Customer(
71+
$email = '[email protected]',
72+
$fullName = 'John Doe',
73+
$phone = '+306987654321',
74+
$countryCode = 'GR',
75+
$requestLang = RequestLang::Greek,
76+
);
77+
78+
$payment = new Payment();
79+
80+
$payment
81+
->setAmount(2500)
82+
->setCustomerTrns('short description of the items/services being purchased')
83+
->setCustomer($customer)
84+
->setPaymentTimeout(3600)
85+
->setPreauth(false)
86+
->setAllowRecurring(true)
87+
->setMaxInstallments(3)
88+
->setPaymentNotification(true)
89+
->setTipAmount(250)
90+
->setDisableExactAmount(false)
91+
->setDisableCash(true)
92+
->setDisableWallet(false)
93+
->setSourceCode(1234)
94+
->setMerchantTrns('customer order reference number')
95+
->setTags(['tag-1', 'tag-2'])
96+
->setBrandColor('009688')
97+
->setPreselectedPaymentMethod(PaymentMethod::PayPal);
98+
99+
$checkoutUrl = VivaWallet::createPaymentOrder($payment);
100+
101+
...
53102
```
54103

55-
## Usage
104+
105+
### Retrieve transaction:
56106

57107
```php
58-
$vivaWallet = new Deyjandi\VivaWallet();
59-
echo $vivaWallet->echoPhrase('Hello, Deyjandi!');
108+
...
109+
110+
use Deyjandi\VivaWallet\Facades\VivaWallet;
111+
112+
...
113+
114+
$transaction = VivaWallet::retrieveTransaction($transactionId);
115+
116+
```
117+
118+
### Request a webhook verification key:
119+
120+
```zsh
121+
php artisan viva-wallet:webhook-key
60122
```
123+
#### the webhook verification key is stored to the `.env` file automatically
124+
61125

62126
## Testing
63127

@@ -80,7 +144,6 @@ Please review [our security policy](../../security/policy) on how to report secu
80144
## Credits
81145

82146
- [Pavlos Kafritsas](https://github.com/Deyjandi)
83-
- [All Contributors](../../contributors)
84147

85148
## License
86149

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"spatie/laravel-package-tools": "^1.9.2"
2626
},
2727
"require-dev": {
28+
"friendsofphp/php-cs-fixer": "^3.8",
2829
"nunomaduro/collision": "^6.0",
2930
"nunomaduro/larastan": "^2.0.1",
3031
"orchestra/testbench": "^7.0",
@@ -48,7 +49,8 @@
4849
}
4950
},
5051
"scripts": {
51-
"analyse": "vendor/bin/phpstan analyse",
52+
"analyse": "vendor/bin/phpstan analyse --memory-limit 256M",
53+
"fix": "vendor/bin/php-cs-fixer fix --config .php_cs.dist.php",
5254
"test": "vendor/bin/pest",
5355
"test-coverage": "vendor/bin/pest --coverage"
5456
},

config/viva-wallet.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
use Deyjandi\VivaWallet\Enums\VivaWalletPaymentMethod;
3+
use Deyjandi\VivaWallet\Enums\PaymentMethod;
44

55
return [
66

@@ -119,7 +119,7 @@
119119

120120
'brand_color' => env('VIVA_WALLET_PAYMENT_BRAND_COLOR', '06abc1'),
121121

122-
'preselected_method' => env('VIVA_WALLET_PAYMENT_PRESELECTED_METHOD', VivaWalletPaymentMethod::CreditCard)
122+
'preselected_method' => env('VIVA_WALLET_PAYMENT_PRESELECTED_METHOD', PaymentMethod::CreditCard)
123123

124124
],
125125
];

database/factories/.gitkeep

Whitespace-only changes.

src/Contracts/AuthToken.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
interface AuthToken
66
{
7-
public static function getInstance(): static;
7+
public static function getInstance(): self;
88

99
public function getAccessToken(): string;
1010

1111
public function getTokenType(): string;
12+
13+
public function refresh(): self;
1214
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace Deyjandi\VivaWallet;
44

5-
use Deyjandi\VivaWallet\Enums\VivaWalletRequestLang;
5+
use Deyjandi\VivaWallet\Enums\RequestLang;
66
use Deyjandi\VivaWallet\Traits\FiltersUnsetData;
77
use InvalidArgumentException;
88

99
/**
1010
* Information about the customer.
1111
*/
12-
class VivaWalletCustomer
12+
class Customer
1313
{
1414
use FiltersUnsetData;
1515

@@ -43,14 +43,14 @@ class VivaWalletCustomer
4343
* It determines the language that Smart Checkout will appear in, and so on.
4444
* If left unspecified it is filled based on the countryCode property.
4545
*/
46-
private ?VivaWalletRequestLang $requestLang;
46+
private ?RequestLang $requestLang;
4747

4848
public function __construct(
4949
?string $email = null,
5050
?string $fullName = null,
5151
?string $phone = null,
5252
?string $countryCode = null,
53-
?VivaWalletRequestLang $requestLang = null,
53+
?RequestLang $requestLang = null,
5454
) {
5555
$this->setEmail($email)
5656
->setFullName($fullName)
@@ -119,7 +119,7 @@ public function setCountryCode(?string $countryCode): static
119119
return $this;
120120
}
121121

122-
public function setRequestLang(?VivaWalletRequestLang $requestLang): static
122+
public function setRequestLang(?RequestLang $requestLang): static
123123
{
124124
$this->requestLang = $requestLang;
125125

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @see https://developer.vivawallet.com/integration-reference/response-codes/#electronic-commerce-indicator
99
*/
10-
enum VivaWalletEci: int
10+
enum Eci: int
1111
{
1212
case Unspecified = 0;
1313
case Authenticated = 1;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace Deyjandi\VivaWallet\Enums;
44

55
use Deyjandi\VivaWallet\Helpers\ClientAuth;
6-
use Deyjandi\VivaWallet\VivaWalletToken;
6+
use Deyjandi\VivaWallet\Token;
77

8-
enum VivaWalletEnv: string
8+
enum Environment: string
99
{
1010
case Demo = 'demo';
1111
case Live = 'live';
@@ -50,7 +50,7 @@ public function createOrder(array $data): array
5050
},
5151
'options' => [
5252
'headers' => [
53-
'Authorization' => ClientAuth::token(VivaWalletToken::getInstance()),
53+
'Authorization' => ClientAuth::token(Token::getInstance()),
5454
'Content-Type' => 'application/json',
5555
],
5656
'json' => $data,
@@ -76,7 +76,7 @@ public function retrieveTransaction(string $transaction_id): array
7676
},
7777
'options' => [
7878
'headers' => [
79-
'Authorization' => ClientAuth::token(VivaWalletToken::getInstance()),
79+
'Authorization' => ClientAuth::token(Token::getInstance()),
8080
],
8181
],
8282
];
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* @see https://developer.vivawallet.com/integration-reference/response-codes/#event-id-codes
77
*/
8-
enum VivaWalletEventId: int
8+
enum EventId: int
99
{
1010
case Undefined = 0;
1111
case Incomplete3dsFlow = 2061;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Deyjandi\VivaWallet\Enums;
44

5-
enum VivaWalletPaymentMethod: int
5+
enum PaymentMethod: int
66
{
77
case CreditCard = 0;
88
case PayPal = 23;

0 commit comments

Comments
 (0)