Skip to content

Commit

Permalink
Merge pull request #1 from shellrent/202101-corrections
Browse files Browse the repository at this point in the history
Data su chiamata di Saldo e miglioramenti minori
  • Loading branch information
tobispace authored Feb 4, 2021
2 parents 56506ea + 4e119ee commit 8906a03
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 16 deletions.
51 changes: 37 additions & 14 deletions src/IntesaSanPaoloClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
class IntesaSanPaoloClient {
/**
* Client HTTP
* @var \GuzzleHttp\Client
*
* @var Client
*/
private $HttpClient;

Expand Down Expand Up @@ -72,7 +73,8 @@ class IntesaSanPaoloClient {

/**
* oAuth2 Bearer
* @var \DateTime
*
* @var DateTime
*/
private $Oauth2BearerExpiry;

Expand Down Expand Up @@ -107,7 +109,8 @@ public function __construct( string $clientId, string $clientSecret, string $iba

/**
* Login: oAuth2 request
* @throws \Shellrent\OpenBanking\Exceptions\Exception
*
* @throws Exception
*/
private function login() {
$response = $this->HttpClient->request( 'POST', $this->Oauth2Url, [
Expand Down Expand Up @@ -135,11 +138,13 @@ private function login() {

/**
* Sends an API request
*
* @param string $method
* @param string $url
* @param array $queryParameters
* @param string $body
* @return \stdClass
*
* @return stdClass
*/
private function request( string $method, string $url, array $queryParameters = [], string $body = null ): ?stdClass {
$now = new DateTime();
Expand Down Expand Up @@ -168,9 +173,11 @@ private function request( string $method, string $url, array $queryParameters =

/**
* Build a Transactions collection
*
* @param string $url
* @param array $params
* @return \Shellrent\OpenBanking\Models\Collections\Transactions
*
* @return Transactions
*/
private function buildTransactions( string $url, array $params = [] ): Transactions {
$transactions = null;
Expand Down Expand Up @@ -211,19 +218,31 @@ private function buildTransactions( string $url, array $params = [] ): Transacti

/**
* Get the current Balance
* @return \Shellrent\OpenBanking\Models\Balance
*
* @param DateTime $date
*
* @throws HttpException
* @return Balance
*/
public function getBalance(): Balance {
$balanceResponse = $this->request( 'GET', sprintf( '%s/accounts/%s/balance', $this->ApiBaseUri, $this->Iban ) );
public function getBalance( DateTime $date ): Balance {
$params = [];

if( $date ) {
$params['date'] = $date->format( 'Ymd' );
}

$balanceResponse = $this->request( 'GET', sprintf( '%s/accounts/%s/balance', $this->ApiBaseUri, $this->Iban ), $params );

return new Balance( $balanceResponse );
}


/**
* Get transactions for a specific date
*
* @param DateTime $date
* @return \Shellrent\OpenBanking\Models\Collections\Transactions
*
* @return Transactions
*/
public function getTransactions( DateTime $date ): Transactions {
return $this->buildTransactions( sprintf( '%s/accounts/%s/transactions', $this->ApiBaseUri, $this->Iban ), [
Expand All @@ -234,8 +253,8 @@ public function getTransactions( DateTime $date ): Transactions {

/**
* Get transactions for today
* @param DateTime $date
* @return \Shellrent\OpenBanking\Models\Collections\Transactions
*
* @return Transactions
*/
public function getTodayTransactions(): Transactions {
return $this->buildTransactions( sprintf( '%s/accounts/%s/transactions/today', $this->ApiBaseUri, $this->Iban ) );
Expand All @@ -244,8 +263,10 @@ public function getTodayTransactions(): Transactions {

/**
* Creates a new Instant Payment (SCT-Instant-Execution)
* @param \Shellrent\OpenBanking\Models\PaymentExecution $payment
* @return \Shellrent\OpenBanking\Models\PaymentExecuted
*
* @param PaymentExecution $payment
*
* @return PaymentExecuted
*/
public function createInstantPayment( PaymentExecution $payment ): PaymentExecuted {
$data = [
Expand Down Expand Up @@ -276,9 +297,11 @@ public function createInstantPayment( PaymentExecution $payment ): PaymentExecut

/**
* Get a list of the payments (SCT Instant - Payments List API)
*
* @param DateTime $fromDate If null, defaults to "1 month ago"
* @param DateTime $toDate
* @return \Shellrent\OpenBanking\Models\Collections\PaymentInfos
*
* @return PaymentInfos
*/
public function getPaymentsList( DateTime $fromDate = null, DateTime $toDate = null ): PaymentInfos {
if( is_null( $fromDate ) ) {
Expand Down
17 changes: 15 additions & 2 deletions src/Models/GenericPaymentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,21 @@ abstract class GenericPaymentData extends GenericPayment {
* @param stdClass $data
*/
protected function hydrateData( stdClass $data ) {
$this->OrderId = $data->{'order-id'};
$this->PaymentId = $data->{'payment-id'};
/* Order ID may be "orderId" or "order-id" depending on the API request */
if( isset( $data->orderId ) ) {
$this->OrderId = $data->orderId;

} elseif( isset( $data->{'order-id'} ) ) {
$this->OrderId = $data->{'order-id'};
}

/* Order ID may be "paymentId" or "payment-id" depending on the API request */
if( isset( $data->paymentId ) ) {
$this->PaymentId = $data->paymentId;

} elseif( isset( $data->{'payment-id'} ) ) {
$this->PaymentId = $data->{'payment-id'};
}

$this->setDebtorName( $data->debtorName );
$this->setDebtorIban( $data->debtorIBAN );
Expand Down

0 comments on commit 8906a03

Please sign in to comment.