Skip to content

Commit

Permalink
patching from tag 0.18.1
Browse files Browse the repository at this point in the history
  • Loading branch information
aliminaei committed Sep 9, 2024
1 parent 5fd242e commit 1f1e506
Show file tree
Hide file tree
Showing 324 changed files with 86,708 additions and 612 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# ref: https://github.com/github/gitignore/blob/master/Composer.gitignore

composer.phar
/vendor/

Expand Down
70 changes: 25 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ require __DIR__ . '/../vendor/autoload.php';
$privateKeyLocation = __DIR__ . "/private_key.pem";

$config = new Gr4vy\Gr4vyConfig("[YOUR_GR4VY_ID]", $privateKeyLocation);
$apiInstance = new Gr4vy\Api\BuyersApi(new GuzzleHttp\Client(),$config->getConfig());

try {
$result = $config->listBuyers();
$result = $apiInstance->listBuyers();
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling listBuyers: ', $e->getMessage(), PHP_EOL;
echo 'Exception when calling BuyersApi->listBuyers: ', $e->getMessage(), PHP_EOL;
}
```

Expand All @@ -51,24 +52,10 @@ $config = new Gr4vy\Gr4vyConfig("[YOUR_GR4VY_ID]", $privateKeyLocation, false, "
## Gr4vy Embed

To create a token for Gr4vy Embed, call the `config->getEmbedToken()` function
with the amount, currency, optional buyer information and optional checkout session for Gr4vy Embed.
with the amount, currency, and optional buyer information for Gr4vy Embed.

```php
//A checkout session allows multiple transaction attempts to be tied together
$checkoutSession = $config->newCheckoutSession();

echo $config->getEmbedToken(
array(
"amount"=> 200,
"currency" => "USD",
"buyer_id"=> "d757c76a-cbd7-4b56-95a3-40125b51b29c"
),
$checkoutSession["id"]
);
```
Or, generate a checkout session and Embed Token with a single call:
```php
echo $config->getEmbedTokenWithCheckoutSession(
array(
"amount"=> 200,
"currency" => "USD",
Expand All @@ -77,7 +64,7 @@ echo $config->getEmbedTokenWithCheckoutSession(
);
```

You can now pass this token to your front end where it can be used to
You can now pass this token to your frontend where it can be used to
authenticate Gr4vy Embed.

The `buyerId` and `buyerExternalIdentifier` fields can be used to allow the
Expand All @@ -86,31 +73,15 @@ be created before it can be used in this way.

```php
$config = new Gr4vy\Gr4vyConfig("[YOUR_GR4VY_ID]", $privateKeyLocation);
$apiInstance = new Gr4vy\Api\BuyersApi(new GuzzleHttp\Client(),$config->getConfig());

$buyer_request = array("external_identifier"=>"412231123","display_name"=>"Tester T.");
$buyer = $config->addBuyer($buyer_request);
$buyer = $apiInstance->addBuyer($buyer_request);

$embed = array("amount"=> 200, "currency" => "USD", "buyer_id"=> $buyer["id"]);
$embed = array("amount"=> 200, "currency" => "USD", "buyer_id"=> $buyer->getId());
$embedToken = $config->getEmbedToken($embed);
```

## Checkout Sessions

A checkout session can be used across Embed sessions to track retries or shopping cart updates. To achieve this the same `checkoutSessionId` can be used in multiple `getEmbedToken` calls.

NOTE: a checkout session is valid for 1h from creation.

```php
$config->getEmbedToken(
array(
"amount"=> 200,
"currency" => "USD",
"buyer_id"=> "d757c76a-cbd7-4b56-95a3-40125b51b29c"
),
$storedCheckoutSessionId
);
```

## Initialization

The client can be initialized with the Gr4vy ID (`gr4vyId`) and the private key.
Expand All @@ -130,34 +101,34 @@ Your API key can be created in your admin panel on the **Integrations** tab.

## Multi merchant

In a multi-merchant environment, the merchant account ID can be set by passing `merchantAccountId` to the Config:
In a multi-merchant environment, the merchant account ID can be set by passing `MerchantAccountHeaderSelector` to the Api:

```php
$config = new Gr4vy\Gr4vyConfig("[YOUR_GR4VY_ID]", $privateKeyLocation, false, "sandbox", "default");

$config = new Gr4vy\Gr4vyConfig("[YOUR_GR4VY_ID]", $privateKeyLocation, false, "sandbox", "my_merchant_account_id");
$headerSelector = new MerchantAccountHeaderSelector("my_merchant_account_id");
$config = new Gr4vyConfig(self::$gr4vyId, self::$privateKeyLocation);
$apiInstance = new BuyersApi(new Client(),$config->getConfig(), $headerSelector);
```

## Making API calls

This library conveniently maps every API path to a seperate function. For example, `GET /buyers?limit=100` would be:

```php
$result = $config->listBuyers(100);
$result = $apiInstance->listBuyers(100);
```

To create or update a resource an `array` should be sent with the request data.

```php
$buyer_request = array("external_identifier"=>"412231123","display_name"=>"Tester T.");
$buyer = $config->addBuyer($buyer_request);
$buyer = $apiInstance->addBuyer($buyer_request);
```

Similarly, to update a buyer you will need to pass in the `BuyerUpdateRequest`.

```php
$buyer_update = array("external_identifier"=>"testUpdateBuyer");
$result = $config->updateBuyer($result["id"], $buyer_update);
$result = $apiInstance->updateBuyer($result->getId(), $buyer_update);
```

## Generate API bearer token
Expand All @@ -166,7 +137,7 @@ The SDK can be used to create API access tokens for use with other request
libraries.

```php
$bearerToken = Gr4vyConfig::getToken($privateKeyLocation, array("*.read", "*.write"))->toString();
$bearerToken = Gr4vyConfig::getToken($privateKeyLocation, array("*.read"))->toString();
```

The first parameter is the location of your private key. The second
Expand Down Expand Up @@ -202,6 +173,15 @@ composer install
./vendor/bin/phpunit test/
```

### Adding new APIs

To add new APIs, run the following command to update the models and APIs based
on the API spec.

```sh
./openapi-generator-generate.sh
```

### Publishing

Publishing of this project is done through [Packagist][packagist]. New versions
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
},
"autoload": {
"psr-4": {
"Gr4vy\\": "lib/"
"Gr4vy\\": "lib/",
"Gr4vy\\Api\\": "lib/api/",
"Gr4vy\\Model\\": "lib/model/"
}
},
"autoload-dev": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1f1e506

Please sign in to comment.