https://github.com/kubinyete/fraugster-sdk-php
Fraugster SDK for PHP 8.x
https://github.com/kubinyete/fraugster-sdk-php
Last synced: 8 months ago
JSON representation
Fraugster SDK for PHP 8.x
- Host: GitHub
- URL: https://github.com/kubinyete/fraugster-sdk-php
- Owner: Kubinyete
- License: mit
- Created: 2022-10-26T19:36:08.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-14T20:27:27.000Z (almost 3 years ago)
- Last Synced: 2025-01-11T18:14:58.819Z (9 months ago)
- Language: PHP
- Size: 153 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
The unofficial Fraugster SDK client for integrating PHP applications
If you have any suggestions or changes please contribute to this project by sending a pull request, the official Fraugster documentation can be found [here](https://docs.fraugster.com/).
## Usage
You can easily start by sending transactions right away with the example provided below,
in this scenario, we are authenticating with two environment variables: `FRAUGSTER_USER` and `FRAUGSTER_SECRET`,
after receiving back a session token, we then proceed to generate a transaction with fake data and attempts to send it.The recommendation details can be accessed via our own `Recommendation` class, wrapping everything and converting
responses to a friendly approach using PHP 8.1 [Enums](https://www.php.net/manual/en/language.enumerations.overview.php).For dispatching sync & async status updates, we provide a simple `UpdatePacket` class that wraps everything needed in every case,
for exemple, if we need to apply an "approved" status to a given transaction, we just need to instantiate an `ApprovedUpdatePacket`,
passing it directly to our client.## Authentication
```php
// Credentials
$username = getenv('FRAUGSTER_USER') ?? '';
$secret = getenv('FRAUGSTER_SECRET') ?? '';// API Client
$client = new FraugsterClient(Environment::staging());
$token = $client->getSessionToken($username, $secret);if (!$token) {
throw new Exception("An error ocurred while trying to authenticate");
} else {
// Sets the current token
$client->useToken($token);
}```
## Sending your first transaction
```php
// Generating a random credit card
$card = $faker->creditCardDetails();
$card = new Card(substr($card['number'], 0, 6), $card['name'], substr($card['number'], strlen($card['number']) - 4), str_replace('/', '', $card['expirationDate']), $card['number']);// Creating a random transaction
$transaction = new Transaction(
($transactionId = 'TRANSACTION_ID' . time()),
new DateTime(),
129.99,
new Currency('BRL'),
'MERCHANT_ID',
true,
new IpAddress($faker->ipv4()),
PaymentMethod::Card,
PaymentMethodBrand::CreditCards,
billing: new Billing($faker->address(), null, null, null, $faker->postcode(), $faker->city(), new State('SP'), new Country($faker->countryCode()), $faker->name()),
shipping: new Shipping($faker->address(), null, null, null, $faker->postcode(), $faker->city(), new State('SP'), new Country($faker->countryCode()), $faker->name(), null),
card: $card,
customer: new Customer($id, (new DateTime('today'))->sub(new DateInterval('P18Y')), new Email($faker->email()), Gender::Male, $faker->name(), true, false),
);// Dispatching to Fraugster
$recommendation = $client->createTransaction($transaction);
echo "Transaction sent received recommendation to {$recommendation->fraugsterApproved()->name}" . PHP_EOL;```
## Updating transaction status```php
// Updating our status based on our previous recommendation.
if ($recommendation->fraugsterApproved() == ApprovedStatus::Approve) {
$client->updateTransaction(new ApprovedUpdatePacket($transactionId, new DateTime(), null));
} else {
$client->updateTransaction(new FrgDeclinedUpdatePacket($transactionId, new DateTime()));
}```