Skip to content

Commit

Permalink
Merge branch 'release-1.3.15'
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumbertin committed Oct 4, 2023
2 parents c808905 + e945932 commit 11ee3a1
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 72 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "paygreen/paygreen-php",
"version": "1.3.14",
"version": "1.3.15",
"description": "PayGreen PHP SDK",
"type": "library",
"license": "proprietary",
Expand Down
11 changes: 11 additions & 0 deletions docs/v3/payment.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ $paymentConfig->setCurrency('eur');
$paymentConfig->setConfig(array('config1', 'config2')); // Optional

$client->createPaymentConfig($paymentConfig, 'sh_0000');
```


## Update a payment config
### :warning: Be careful, the `selling_contract` property cannot be updated with SDK
```php
$paymentConfig = new \Paygreen\Sdk\Payment\V3\Model\PaymentConfig();
$paymentConfig->setStatus('value');
$paymentConfig->setConfig(['key' => 'value']);

$client->updatePaymentConfig('pc_0000', $paymentConfig);
```

# Transaction
Expand Down
27 changes: 25 additions & 2 deletions lib/PaygreenSdk/Payment/V3/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Paygreen\Sdk\Payment\V3\Model\Instrument;
use Paygreen\Sdk\Payment\V3\Model\ListenerInterface;
use Paygreen\Sdk\Payment\V3\Model\Operation;
use Paygreen\Sdk\Payment\V3\Model\PaymentConfig;
use Paygreen\Sdk\Payment\V3\Model\PaymentConfigInterface;
use Paygreen\Sdk\Payment\V3\Model\PaymentOrder;
use Paygreen\Sdk\Payment\V3\Model\Shop;
Expand Down Expand Up @@ -69,6 +70,22 @@ public function authenticate()
return $response;
}

/**
* @return ResponseInterface
* @throws Exception
*
*/
public function getPublicKey($publicKey)
{
$request = (new PublicKeyRequest($this->requestFactory, $this->environment))->getGetRequest($publicKey);
$this->setLastRequest($request);

$response = $this->sendRequest($request);
$this->setLastResponse($response);

return $response;
}

/**
* @param string $paymentConfigId
*
Expand Down Expand Up @@ -135,13 +152,19 @@ public function createPaymentConfig(PaymentConfigInterface $paymentConfig, $shop
}

/**
* @link https://developers.paygreen.fr/reference/post_update_payment_config
*
* @param string $shopId
* @param PaymentConfig $shop
*
* @return ResponseInterface
* @throws Exception
*
*/
public function getPublicKey($publicKey)
public function updatePaymentConfig($paymentConfigId, PaymentConfigInterface $paymentConfig)
{
$request = (new PublicKeyRequest($this->requestFactory, $this->environment))->getGetRequest($publicKey);
$request = (new PaymentConfigRequest($this->requestFactory, $this->environment))
->getUpdateRequest($paymentConfigId, $paymentConfig);
$this->setLastRequest($request);

$response = $this->sendRequest($request);
Expand Down
42 changes: 42 additions & 0 deletions lib/PaygreenSdk/Payment/V3/Model/PaymentConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

class PaymentConfig implements PaymentConfigInterface
{
/**
* @var string
*/
private $id;

/**
* @var string
*/
private $status;

/**
* @var string
*/
Expand All @@ -24,6 +34,38 @@ class PaymentConfig implements PaymentConfigInterface
*/
private $config = array();

/**
* @return string
*/
public function getId()
{
return $this->id;
}

/**
* @param string $id
*/
public function setId($id)
{
$this->id = $id;
}

/**
* @return string
*/
public function getStatus()
{
return $this->status;
}

/**
* @param string $status
*/
public function setStatus($status)
{
$this->status = $status;
}

/**
* @return string
*/
Expand Down
15 changes: 15 additions & 0 deletions lib/PaygreenSdk/Payment/V3/Model/PaymentConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@

interface PaymentConfigInterface
{
/**
* @return string
*/
public function getId();

/**
* @return string
*/
public function getStatus();

/**
* @param string $status
*/
public function setStatus($status);

/**
* @return string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Paygreen\Sdk\Payment\V3\Request\PaymentConfig;

use GuzzleHttp\Psr7\Request;
use Paygreen\Sdk\Core\Encoder\JsonEncoder;
use Paygreen\Sdk\Core\Normalizer\CleanEmptyValueNormalizer;
use Paygreen\Sdk\Core\Serializer\Serializer;
use Paygreen\Sdk\Payment\V3\Model\PaymentConfig;
use Paygreen\Sdk\Payment\V3\Model\PaymentConfigInterface;
use Psr\Http\Message\RequestInterface;

Expand Down Expand Up @@ -62,4 +64,33 @@ public function getCreateRequest(PaymentConfigInterface $paymentConfig, $shopId
(new Serializer([new CleanEmptyValueNormalizer()], [new JsonEncoder()]))->serialize($body, 'json')
)->withAuthorization()->isJson()->getRequest();
}

/**
* @param string $paymentConfigId
* @param PaymentConfig $paymentConfig
*
* @return Request|RequestInterface
*/
public function getUpdateRequest($paymentConfigId, $paymentConfig)
{
$body = $this->getBodyData($paymentConfig);

return $this->requestFactory->create(
'/payment/payment-configs/' . urlencode($paymentConfigId),
(new Serializer([new CleanEmptyValueNormalizer()], [new JsonEncoder()]))->serialize($body, 'json')
)->withAuthorization()->isJson()->getRequest();
}

/**
* @param PaymentConfigInterface $paymentConfig
*
* @return array
*/
public function getBodyData(PaymentConfigInterface $paymentConfig)
{
return [
'status' => $paymentConfig->getStatus(),
'config' => $paymentConfig->getConfig()
];
}
}
132 changes: 74 additions & 58 deletions tests/Application/payment_v3.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

$curl = new Client();



$environment = new Environment(
getenv('PG_PAYMENT_SHOP_ID'), //PG_PAYMENT_SHOP_ID SHOP_ID_MARKETPLACE
getenv('PG_PAYMENT_SECRET_KEY'), //PG_PAYMENT_SECRET_KEY SECRET_KEY_MARKETPLACE
Expand All @@ -30,67 +28,85 @@
$bearer = $data->token;
$client->setBearer($bearer);

die();

//UPDATE SHOP

$response = $client->updateShop(
$environment->getShopId(),
(new \Paygreen\Sdk\Payment\V3\Model\Shop())->setName('Nouveau Nom')
);

$jsonResponse = json_decode($response->getBody()->getContents());
$data = $jsonResponse->data;

//LIST AND UPDATE PC
//$response = $client->listPaymentConfig('shop_id');
//$pcs = json_decode($response->getBody()->getContents());
//
//if(count($pcs->data) > 0) {
// foreach ($pcs->data as $pc) {
// $updatePc = new \Paygreen\Sdk\Payment\V3\Model\PaymentConfig();
//// $updatePc->setStatus('enabled');
// $updatePc->setConfig(['reuse_card_proposal' => true]);
//
// $resp = $client->updatePaymentConfig($pc->id, $updatePc);
// dump($resp->getStatusCode(), $resp->getBody()->getContents());
// }
//}
//
//die();

dump($data); die();
//UPDATE SHOP
//$response = $client->updateShop(
// $environment->getShopId(),
// (new \Paygreen\Sdk\Payment\V3\Model\Shop())->setName('Nouveau Nom')
//);
//
//$jsonResponse = json_decode($response->getBody()->getContents());
//$data = $jsonResponse->data;
//
//dump($data); die();


// List Payment Order
$filters = [
'reference' => 'Lorem ipsum'
];
$pagination = [
'max_per_page' => 19,
'page' => 2
];

$response = $client->listPaymentOrder(null, null, $filters, $pagination);

$jsonResponse = json_decode($response->getBody()->getContents());
$data = $jsonResponse->data;
$pagination = $jsonResponse->pagination;


dump($data,$pagination); die();
$filters = [
'email' => '[email protected]'
];

// pagination settings
$pagination = [
'max_per_page' => 10,
'page' => 1
];

// call
$response = $client->listBuyer($filters, $pagination);

// response
$jsonResponse = json_decode($response->getBody()->getContents());
$data = $jsonResponse->data;
$pagination = $jsonResponse->pagination;

dump("count buyer:" . count($data));

foreach ($data as $index => $buyer) {
$responsePC = $client->getBuyer($buyer->id);
dump($responsePC);
$jsonResponsePC = json_decode($responsePC->getBody()->getContents());
$dataPC = $jsonResponsePC->data;
dump($dataPC);
die();
}
die();
//$filters = [
// 'reference' => 'Lorem ipsum'
//];
//$pagination = [
// 'max_per_page' => 19,
// 'page' => 2
//];
//
//$response = $client->listPaymentOrder(null, null, $filters, $pagination);
//
//$jsonResponse = json_decode($response->getBody()->getContents());
//$data = $jsonResponse->data;
//$pagination = $jsonResponse->pagination;
//
//
//dump($data,$pagination); die();

// List Buyer
//$filters = [
// 'email' => '[email protected]'
//];
//
//// pagination settings
//$pagination = [
// 'max_per_page' => 10,
// 'page' => 1
//];
//
//// call
//$response = $client->listBuyer($filters, $pagination);
//
//// response
//$jsonResponse = json_decode($response->getBody()->getContents());
//$data = $jsonResponse->data;
//$pagination = $jsonResponse->pagination;
//
//dump("count buyer:" . count($data));
//
//foreach ($data as $index => $buyer) {
// $responsePC = $client->getBuyer($buyer->id);
// dump($responsePC);
// $jsonResponsePC = json_decode($responsePC->getBody()->getContents());
// $dataPC = $jsonResponsePC->data;
// dump($dataPC);
// die();
//}
//die();

/*$response = $client->listTransaction();
dump($response);
Expand Down
Loading

0 comments on commit 11ee3a1

Please sign in to comment.