...
 
Commits (2)
<?php
/**
*
*/
namespace Minds\Controllers\api\v2\payments\stripe;
use Minds\Api\Factory;
use Minds\Common\Cookie;
use Minds\Core\Di\Di;
use Minds\Core\Config;
use Minds\Core\Session;
use Minds\Interfaces;
use Minds\Core\Payments\Stripe;
class transactions implements Interfaces\Api
{
public function get($pages)
{
$user = Session::getLoggedInUser();
$connectManager = new Stripe\Connect\Manager();
try {
$account = $connectManager->getByUser($user);
} catch (\Exception $e) {
return Factory::response([
'status' => 'error',
'message' => 'There was an error returning the usd account',
]);
}
$transactionsManger = new Stripe\Transactions\Manager();
$transactions = $transactionsManger->getByAccount($account);
return Factory::response([
'transactions' => Factory::exportable($transactions),
]);
}
public function post($pages)
{
return Factory::response([]);
}
public function put($pages)
{
return Factory::response([]);
}
public function delete($pages)
{
return Factory::response([]);
}
}
<?php
namespace Minds\Core\Payments\Stripe\Instances;
use Minds\Common\StaticToInstance;
use Minds\Core\Config\Config;
use Minds\Core\Di\Di;
/**
* @method ChargeInstance retrieve()
*/
class ChargeInstance extends StaticToInstance
{
public function __construct(Config $config = null)
{
$config = $config ?? Di::_()->get('Config');
\Stripe\Stripe::setApiKey($config->get('payments')['stripe']['api_key']);
$this->setClass(new \Stripe\Charge);
}
}
<?php
namespace Minds\Core\Payments\Stripe\Instances;
use Minds\Common\StaticToInstance;
use Minds\Core\Config\Config;
use Minds\Core\Di\Di;
/**
* @method TransferInstance all()
*/
class TransferInstance extends StaticToInstance
{
public function __construct(Config $config = null)
{
$config = $config ?? Di::_()->get('Config');
\Stripe\Stripe::setApiKey($config->get('payments')['stripe']['api_key']);
$this->setClass(new \Stripe\Transfer);
}
}
......@@ -63,6 +63,9 @@ class Manager
'transfer_data' => [
'destination' => $intent->getStripeAccountId(),
],
'metadata' => [
'user_guid' => $intent->getUserGuid(),
],
];
if ($intent->getServiceFee()) {
......
<?php
namespace Minds\Core\Payments\Stripe\Transactions;
use Minds\Core\Payments\Stripe\Connect\Account;
use Minds\Core\Payments\Stripe\Instances\TransferInstance;
use Minds\Core\Payments\Stripe\Instances\ChargeInstance;
use Minds\Core\Di\Di;
use Minds\Common\Repository\Response;
class Manager
{
/** @var EntitiesBuilder $entitiesBuilder */
private $entitiesBuilder;
/** @var TransferInstance $transferInstance */
private $transferInstance;
/** @var ChargeInstance $chargeInstance */
private $chargeInstance;
public function __construct($entitiesBuilder = null, $transferInstance = null, $chargeInstance = null)
{
$this->entitiesBuilder = $entitiesBuilder ?? Di::_()->get('EntitiesBuilder');
$this->transferInstance = $transferInstance ?? new TransferInstance();
$this->chargeInstance = $chargeInstance ?? new ChargeInstance();
}
/**
* Return transactions from an account object
* @param Account $account
* @return Response[Transaction]
*/
public function getByAccount(Account $account): Response
{
$transfers = $this->transferInstance->all([ 'destination' => $account->getId() ]);
$response = new Response();
foreach ($transfers->autoPagingIterator() as $transfer) {
try {
$payment = $this->chargeInstance->retrieve($transfer->source_transaction);
} catch (\Exception $e) {
continue;
}
$transaction = new Transaction();
$transaction->setId($transfer->id)
->setTimestamp($transfer->created)
->setGross($payment->amount)
->setFees(0)
->setNet($transfer->amount)
->setCurrency($transfer->currency)
->setCustomerUserGuid($payment->metadata['user_guid'])
->setCustomerUser($this->entitiesBuilder->single($payment->metadata['user_guid']));
$response[] = $transaction;
}
return $response;
}
}
<?php
namespace Minds\Core\Payments\Stripe\Transactions;
use Minds\Entities\User;
use Minds\Traits\MagicAttributes;
class Transaction
{
use MagicAttributes;
/** @var string $id */
private $id;
/** @var int $timestamp */
private $timestamp;
/** @var int $gross */
private $gross;
/** @var string $currency */
private $currency;
/** @var int $fees */
private $fees;
/** @var int $net */
private $net;
/** @var string $customerGuid */
private $customerUserGuid;
/** @var User $customerUser */
private $customerUser;
/**
* Expose to the public apis
* @param array $extend
* @return array
*/
public function export(array $extend = []) : array
{
return [
'id' => $this->id,
'timestamp' => $this->timestamp,
'gross' => $this->gross,
'currency' => $this->currency,
'fees' => $this->fees,
'net' => $this->net,
'customer_user_guid' => $this->userGuid,
'customer_user' => $this->customerUser ? $this->customerUser->export() : null,
];
}
}
......@@ -266,7 +266,7 @@ class Manager
throw new \Exception("Not implemented ETH yet");
break;
case 'usd':
if (!$this->receiver->getMerchant() || $this->receiver->getMerchant()['id']) {
if (!$this->receiver->getMerchant() || !$this->receiver->getMerchant()['id']) {
throw new \Exception("This channel is not able to receive USD at the moment");
}
$intent = new PaymentIntent();
......