Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Dependency List
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
175
Issues
175
List
Boards
Labels
Service Desk
Milestones
Merge Requests
40
Merge Requests
40
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
c2099aa6
Commit
c2099aa6
authored
20 minutes ago
by
Mark Harding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(feat): working stripe with wire
parent
d4433729
No related merge requests found
Pipeline
#72528990
failed with stages
in 4 minutes
Changes
22
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
945 additions
and
118 deletions
+945
-118
Stripe.php
Controllers/Cli/Stripe.php
+74
-0
intents.php
Controllers/api/v2/payments/stripe/intents.php
+82
-0
paymentmethods.php
Controllers/api/v2/payments/stripe/paymentmethods.php
+83
-0
wire.php
Controllers/api/v2/wire.php
+116
-0
PaymentsProvider.php
Core/Payments/PaymentsProvider.php
+4
-0
Manager.php
Core/Payments/Stripe/Customers/Manager.php
+19
-9
CustomerInstance.php
Core/Payments/Stripe/Instances/CustomerInstance.php
+23
-0
PaymentIntentInstance.php
Core/Payments/Stripe/Instances/PaymentIntentInstance.php
+23
-0
PaymentMethodInstance.php
Core/Payments/Stripe/Instances/PaymentMethodInstance.php
+23
-0
SetupIntentInstance.php
Core/Payments/Stripe/Instances/SetupIntentInstance.php
+23
-0
Intent.php
Core/Payments/Stripe/Intents/Intent.php
+10
-23
Manager.php
Core/Payments/Stripe/Intents/Manager.php
+80
-7
PaymentIntent.php
Core/Payments/Stripe/Intents/PaymentIntent.php
+51
-0
SetupIntent.php
Core/Payments/Stripe/Intents/SetupIntent.php
+23
-0
Manager.php
Core/Payments/Stripe/PaymentMethods/Manager.php
+95
-0
PaymentMethod.php
Core/Payments/Stripe/PaymentMethods/PaymentMethod.php
+52
-0
Stripe.php
Core/Payments/Stripe/Stripe.php
+2
-2
CacheDelegate.php
Core/Wire/Delegates/CacheDelegate.php
+30
-0
NotificationDelegate.php
Core/Wire/Delegates/NotificationDelegate.php
+35
-0
RecurringDelegate.php
Core/Wire/Delegates/RecurringDelegate.php
+46
-0
Manager.php
Core/Wire/Manager.php
+47
-76
Wire.php
Core/Wire/Wire.php
+4
-1
No files found.
Controllers/Cli/Stripe.php
0 → 100644
View file @
c2099aa6
<?php
namespace
Minds\Controllers\Cli
;
use
Minds\Core
;
use
Minds\Core\Di\Di
;
use
Minds\Cli
;
use
Minds\Interfaces
;
use
Minds\Exceptions
;
use
Minds\Entities
;
use
Minds\Core\Data\ElasticSearch\Prepared
;
use
Minds\Core\Analytics\Iterators\SignupsOffsetIterator
;
use
Minds\Core\Boost\Network\Manager
;
use
Minds\Core\Util\BigNumber
;
use
Minds\Helpers\Counters
;
class
Stripe
extends
Cli\Controller
implements
Interfaces\CliControllerInterface
{
private
$db
;
private
$es
;
private
$elasticRepository
;
private
$pendingBulkInserts
=
[];
public
function
__construct
()
{
error_reporting
(
E_ALL
);
ini_set
(
'display_errors'
,
1
);
}
public
function
help
(
$command
=
null
)
{
$this
->
out
(
'TBD'
);
}
public
function
exec
()
{
echo
"1"
;
}
public
function
get_payment_intent
()
{
$intent
=
new
Core\Payments\Stripe\Intents\PaymentIntent
();
$intent
->
setAmount
(
2000
);
$intentManager
=
new
Core\Payments\Stripe\Intents\Manager
();
$intent
=
$intentManager
->
add
(
$intent
);
var_dump
(
$intent
);
}
public
function
get_setup_intent
()
{
$intent
=
new
Core\Payments\Stripe\Intents\SetupIntent
();
$intentManager
=
new
Core\Payments\Stripe\Intents\Manager
();
$intent
=
$intentManager
->
add
(
$intent
);
var_dump
(
$intent
->
getClientSecret
());
}
public
function
get_setup_intent_payment_method
()
{
$id
=
$this
->
getOpt
(
'id'
);
$intentManager
=
new
Core\Payments\Stripe\Intents\Manager
();
$intent
=
$intentManager
->
get
(
$id
);
var_dump
(
$intent
);
}
}
This diff is collapsed.
Click to expand it.
Controllers/api/v2/payments/stripe/intents.php
0 → 100644
View file @
c2099aa6
<?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
intents
implements
Interfaces\Api
{
public
function
get
(
$pages
)
{
return
Factory
::
response
([
]);
}
public
function
post
(
$pages
)
{
$user
=
Session
::
getLoggedInUser
();
switch
(
$pages
[
0
])
{
case
'apply'
:
$intent
=
new
Stripe\Intents\SetupIntent
();
$intent
->
setId
(
$_POST
[
'intent_id'
]);
$intentManager
=
new
Stripe\Intents\Manager
();
$intent
=
$intentManager
->
get
(
$_POST
[
'intent_id'
]);
$customersManager
=
new
Stripe\Customers\Manager
();
$customer
=
$customersManager
->
getFromUserGuid
(
$user
->
getGuid
());
if
(
!
$customer
)
{
$customer
=
new
Stripe\Customers\Customer
;
$customer
->
setUser
(
$user
)
->
setUserGuid
(
$user
->
getGuid
());
}
$customer
->
setPaymentMethod
(
$intent
->
getPaymentMethod
());
$customersManager
->
updatePaymentMethod
(
$customer
);
var_dump
(
$customer
);
exit
;
break
;
}
return
Factory
::
response
([]);
}
public
function
put
(
$pages
)
{
$user
=
Session
::
getLoggedInUser
();
$intent
=
new
Stripe\Intents\SetupIntent
();
$intentManager
=
new
Stripe\Intents\Manager
();
$intent
=
$intentManager
->
add
(
$intent
);
return
Factory
::
response
([
'intent'
=>
$intent
->
export
(),
]);
}
public
function
delete
(
$pages
)
{
$user
=
Session
::
getLoggedInUser
();
$user
->
setCanary
(
false
);
$user
->
save
();
return
Factory
::
response
([]);
}
}
This diff is collapsed.
Click to expand it.
Controllers/api/v2/payments/stripe/paymentmethods.php
0 → 100644
View file @
c2099aa6
<?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
paymentmethods
implements
Interfaces\Api
{
public
function
get
(
$pages
)
{
$user
=
Session
::
getLoggedInUser
();
$paymentMethodsManager
=
new
Stripe\PaymentMethods\Manager
();
$paymentMethods
=
$paymentMethodsManager
->
getList
([
'limit'
=>
12
,
'user_guid'
=>
$user
->
getGuid
(),
]);
return
Factory
::
response
([
'paymentmethods'
=>
Factory
::
exportable
(
$paymentMethods
),
]);
}
public
function
post
(
$pages
)
{
$user
=
Session
::
getLoggedInUser
();
switch
(
$pages
[
0
])
{
case
'apply'
:
$intent
=
new
Stripe\Intents\SetupIntent
();
$intent
->
setId
(
$_POST
[
'intent_id'
]);
$intentManager
=
new
Stripe\Intents\Manager
();
$paymentMethodsManager
=
new
Stripe\PaymentMethods\Manager
();
$customersManager
=
new
Stripe\Customers\Manager
();
// Get the intent
$intent
=
$intentManager
->
get
(
$_POST
[
'intent_id'
]);
// Grab our customerId
$customer
=
$customersManager
->
getFromUserGuid
(
$user
->
getGuid
());
// Build a payment method
$paymentMethod
=
new
Stripe\PaymentMethods\PaymentMethod
();
$paymentMethod
->
setId
(
$intent
->
getPaymentMethod
())
->
setUserGuid
(
$user
->
getGuid
());
if
(
$customer
)
{
$paymentMethod
->
setCustomerId
(
$customer
->
getId
());
}
// Save the payment method
$paymentMethodsManager
->
add
(
$paymentMethod
);
break
;
}
return
Factory
::
response
([]);
}
public
function
put
(
$pages
)
{
return
Factory
::
response
([]);
}
public
function
delete
(
$pages
)
{
$paymentMethodsManager
=
new
Stripe\PaymentMethods\Manager
();
$paymentMethodsManager
->
delete
(
$pages
[
0
]);
return
Factory
::
response
([]);
}
}
This diff is collapsed.
Click to expand it.
Controllers/api/v2/wire.php
0 → 100644
View file @
c2099aa6
<?php
/**
* Minds Wire Api endpoint.
*
* @version 2
*
* @author Mark Harding
*/
namespace
Minds\Controllers\api\v2
;
use
Minds\Api\Factory
;
use
Minds\Core
;
use
Minds\Core\Util\BigNumber
;
use
Minds\Core\Wire\Exceptions\WalletNotSetupException
;
use
Minds\Entities
;
use
Minds\Interfaces
;
class
wire
implements
Interfaces\Api
{
public
function
get
(
$pages
)
{
$response
=
[];
return
Factory
::
response
(
$response
);
}
/**
* Send a wire to someone.
*
* @param array $pages
*
* API:: /v1/wire/:guid
*/
public
function
post
(
$pages
)
{
Factory
::
isLoggedIn
();
$response
=
[];
if
(
!
isset
(
$pages
[
0
]))
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
':guid must be passed in uri'
]);
}
$entity
=
Entities\Factory
::
build
(
$pages
[
0
]);
if
(
!
$entity
)
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
'Entity not found'
]);
}
$user
=
$entity
->
type
==
'user'
?
$entity
:
$entity
->
getOwnerEntity
();
if
(
Core\Session
::
getLoggedInUserGuid
()
===
$user
->
guid
)
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
'You cannot send a wire to yourself!'
]);
}
if
(
Core\Security\ACL\Block
::
_
()
->
isBlocked
(
Core\Session
::
getLoggedInUserGuid
(),
$user
->
guid
))
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
'You cannot send a wire to a user who has blocked you.'
]);
}
$amount
=
BigNumber
::
_
(
$_POST
[
'amount'
]);
$recurring
=
isset
(
$_POST
[
'recurring'
])
?
$_POST
[
'recurring'
]
:
false
;
if
(
!
$amount
)
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
'you must send an amount'
]);
}
if
(
$amount
->
lt
(
0
))
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
'amount must be a positive number'
]);
}
$manager
=
Core\Di\Di
::
_
()
->
get
(
'Wire\Manager'
);
$digits
=
18
;
if
(
$_POST
[
'method'
]
===
'usd'
)
{
$digits
=
2
;
}
try
{
$manager
->
setAmount
((
string
)
BigNumber
::
toPlain
(
$amount
,
$digits
))
->
setRecurring
(
$recurring
)
->
setSender
(
Core\Session
::
getLoggedInUser
())
->
setEntity
(
$entity
)
->
setPayload
((
array
)
$_POST
[
'payload'
]);
$result
=
$manager
->
create
();
if
(
!
$result
)
{
throw
new
\Exception
(
'Something failed'
);
}
}
catch
(
WalletNotSetupException
$e
)
{
$wireQueue
=
(
Queue\Client
::
Build
())
->
setQueue
(
'WireNotification'
)
->
send
([
'entity'
=>
serialize
(
$entity
),
'walletNotSetupException'
=>
true
,
]);
$response
[
'status'
]
=
'error'
;
$response
[
'message'
]
=
$e
->
getMessage
();
}
catch
(
\Exception
$e
)
{
$response
[
'status'
]
=
'error'
;
$response
[
'message'
]
=
$e
->
getMessage
();
}
return
Factory
::
response
(
$response
);
}
public
function
put
(
$pages
)
{
}
public
function
delete
(
$pages
)
{
}
}
This diff is collapsed.
Click to expand it.
Core/Payments/PaymentsProvider.php
View file @
c2099aa6
...
...
@@ -57,5 +57,9 @@ class PaymentsProvider extends Provider
$this
->
di
->
bind
(
'Stripe\Connect\Manager'
,
function
(
$di
)
{
return
new
Stripe\Connect\Manager
();
},
[
'useFactory'
=>
true
]);
$this
->
di
->
bind
(
'Stripe\Intents\Manager'
,
function
(
$di
)
{
return
new
Stripe\Intents\Manager
();
},
[
'useFactory'
=>
true
]);
}
}
This diff is collapsed.
Click to expand it.
Core/Payments/Stripe/Customers/Manager.php
View file @
c2099aa6
...
...
@@ -3,6 +3,8 @@
namespace
Minds\Core\Payments\Stripe\Customers
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Payments\Stripe\Instances\CustomerInstance
;
use
Minds\Core\Payments\Stripe\Instances\PaymentMethodInstance
;
class
Manager
{
...
...
@@ -10,9 +12,15 @@ class Manager
/** @var Lookup $lookup */
private
$lookup
;
public
function
__construct
(
$lookup
=
null
)
private
$customerInstance
;
private
$paymentMethodInstance
;
public
function
__construct
(
$lookup
=
null
,
$customerInstance
=
null
,
$paymentMethodInstance
=
null
)
{
$this
->
lookup
=
$lookup
?:
Di
::
_
()
->
get
(
'Database\Cassandra\Lookup'
);
$this
->
customerInstance
=
$customerInstance
??
new
CustomerInstance
();
$this
->
paymentMethodInstance
=
$paymentMethodInstance
??
new
PaymentMethodInstance
();
}
/**
...
...
@@ -47,18 +55,20 @@ class Manager
* @param Customer $customer
* @return boolean
*/
public
function
add
(
Customer
$customer
)
public
function
add
(
Customer
$customer
)
:
Customer
{
$customer
=
\Stripe\Customer
::
create
([
'source'
=>
$customer
->
getPaymentSource
(),
'email'
=>
$customer
->
getUser
()
->
getEmail
(),
]);
$stripeCustomer
=
$this
->
customerInstance
->
create
([
'payment_method'
=>
$customer
->
getPaymentMethod
(),
]);
$this
->
lu
->
set
(
"
{
$customer
->
getUserGuid
()
}
:payments"
,
[
'customer_id'
=>
(
string
)
$
c
ustomer
->
id
'customer_id'
=>
(
string
)
$
stripeC
ustomer
->
id
]);
return
(
bool
)
$customer
->
id
;
$customer
->
setId
(
$stripeCustomer
->
id
);
return
$customer
;
}
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
Core/Payments/Stripe/Instances/CustomerInstance.php
0 → 100644
View file @
c2099aa6
<?php
namespace
Minds\Core\Payments\Stripe\Instances
;
use
Minds\Common\StaticToInstance
;
use
Minds\Core\Config\Config
;
use
Minds\Core\Di\Di
;
/**
* @method AccountInstance create()
* @method AccountInstance retrieve()
*/
class
CustomerInstance
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\Customer
);
}
}
This diff is collapsed.
Click to expand it.
Core/Payments/Stripe/Instances/PaymentIntentInstance.php
0 → 100644
View file @
c2099aa6
<?php
namespace
Minds\Core\Payments\Stripe\Instances
;
use
Minds\Common\StaticToInstance
;
use
Minds\Core\Config\Config
;
use
Minds\Core\Di\Di
;
/**
* @method AccountInstance create()
* @method AccountInstance retrieve()
*/
class
PaymentIntentInstance
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\PaymentIntent
);
}
}
This diff is collapsed.
Click to expand it.
Core/Payments/Stripe/Instances/PaymentMethodInstance.php
0 → 100644
View file @
c2099aa6
<?php
namespace
Minds\Core\Payments\Stripe\Instances
;
use
Minds\Common\StaticToInstance
;
use
Minds\Core\Config\Config
;
use
Minds\Core\Di\Di
;
/**
* @method AccountInstance create()
* @method AccountInstance retrieve()
*/
class
PaymentMethodInstance
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\PaymentMethod
);
}
}
This diff is collapsed.
Click to expand it.
Core/Payments/Stripe/Instances/SetupIntentInstance.php
0 → 100644
View file @
c2099aa6
<?php
namespace
Minds\Core\Payments\Stripe\Instances
;
use
Minds\Common\StaticToInstance
;
use
Minds\Core\Config\Config
;
use
Minds\Core\Di\Di
;
/**
* @method AccountInstance create()
* @method AccountInstance retrieve()
*/
class
SetupIntentInstance
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\SetupIntent
);
}
}
This diff is collapsed.
Click to expand it.
Core/Payments/Stripe/Intents/Intent.php
View file @
c2099aa6
...
...
@@ -11,34 +11,19 @@ class Intent
use
MagicAttributes
;
/** @var string $id */
private
$id
;
/** @var int $amount */
private
$amount
=
0
;
/** @var int $quantity */
private
$quantity
=
1
;
/** @var string $currency */
private
$currency
=
'usd'
;
/** @var int $serviceFeePct */
private
$serviceFeePct
=
0
;
protected
$id
;
/** @var string $customerId */
private
$customerId
;
protected
$customerId
;
/** @var string $paymentMethod */
protected
$paymentMethod
;
/** @var string $stripeAccountId */
pr
ivate
$stripeAccountId
;
pr
otected
$stripeAccountId
;
/**
* Return the service
* @return int
*/
public
function
getServiceFee
()
:
int
{
return
$this
->
amount
*
(
$this
->
serviceFeePct
/
100
);
}
/** @var string $clientSecret */
protected
$clientSecret
;
/**
* Expose to the public apis
...
...
@@ -48,6 +33,8 @@ class Intent
public
function
export
(
$extend
=
[])
{
return
[
'id'
=>
$this
->
id
,
'client_secret'
=>
$this
->
clientSecret
,
];
}
...
...
This diff is collapsed.
Click to expand it.
Core/Payments/Stripe/Intents/Manager.php
View file @
c2099aa6
...
...
@@ -2,32 +2,105 @@
namespace
Minds\Core\Payments\Stripe\Intents
;
use
Minds\Core\Payments\Stripe\Customers\Manager
as
CustomersManager
;
use
Minds\Core\Payments\Stripe\Instances\PaymentIntentInstance
;
use
Minds\Core\Payments\Stripe\Instances\SetupIntentInstance
;
class
Manager
{
/** @var CustomersManager $customersManager */
private
$customersManager
;
/** @var PaymentIntentInstance $paymentIntentInstance */
private
$paymentIntentInstance
;
/** @var SetupIntentInstance $setupIntentInstance */
private
$setupIntentInstance
;
public
function
__construct
(
CustomersManager
$customersManager
=
null
,
PaymentIntentInstance
$paymentIntentInstance
=
null
,
SetupIntentInstance
$setupIntentInstance
=
null
)
{
$this
->
customersManager
=
$customersManager
??
new
CustomersManager
;
$this
->
paymentIntentInstance
=
$paymentIntentInstance
?:
new
PaymentIntentInstance
();
$this
->
setupIntentInstance
=
$setupIntentInstance
?:
new
SetupIntentInstance
();
}
/**
* Add a payment intent to stripe
* @param Intent $intent
* @return string
*/
public
function
add
(
Intent
$intent
)
:
string
public
function
add
(
Intent
$intent
)
:
Intent
{
switch
(
true
)
{
case
$intent
instanceof
PaymentIntent
:
return
$this
->
addPayment
(
$intent
);
break
;
case
$intent
instanceof
SetupIntent
:
return
$this
->
addSetup
(
$intent
);
break
;
default
:
throw
new
\Exception
(
'Intent not supported or not an intent'
);
}
}
private
function
addPayment
(
PaymentIntent
$intent
)
:
PaymentIntent
{
$customer
=
$this
->
customersManager
->
getFromUserGuid
(
$intent
->
getUserGuid
());
$params
=
[
'amount'
=>
$intent
->
getAmount
(),
'currency'
=>
$intent
->
getCurrency
(),
'setup_future_usage'
=>
'off_session'
,
'payment_method_types'
=>
[
'card'
,
],
'application_fee_amount'
=>
$intent
->
getServiceFee
(),
'customer'
=>
$customer
->
getId
(),
'payment_method'
=>
$intent
->
getPaymentMethod
(),
'off_session'
=>
$intent
->
isOffSession
(),
'confirm'
=>
$intent
->
isConfirm
(),
'on_behalf_of'
=>
$intent
->
getStripeAccountId
(),
'transfer_data'
=>
[
'destination'
=>
$
order
->
getStripeAccountId
(),
'destination'
=>
$
intent
->
getStripeAccountId
(),
],
];
$stripeIntent
=
\Stripe\PaymentIntent
::
create
(
$params
);
if
(
$intent
->
getServiceFee
())
{
$params
[
'application_fee_amount'
]
=
$intent
->
getServiceFee
();
}
$stripeIntent
=
$this
->
paymentIntentInstance
->
create
(
$params
);
$intent
->
setId
(
$stripeIntent
->
id
);
return
$intent
;
}
private
function
addSetup
(
SetupIntent
$intent
)
:
SetupIntent
{
$params
=
[
'usage'
=>
'off_session'
,
];
$stripeIntent
=
$this
->
setupIntentInstance
->
create
(
$params
);
$intent
->
setId
(
$stripeIntent
->
id
)
->
setClientSecret
(
$stripeIntent
->
client_secret
);
return
$intent
;
}
public
function
get
(
$id
)
{
$stripeIntent
=
$this
->
setupIntentInstance
->
retrieve
(
$id
);
$intent
=
new
SetupIntent
();
$intent
->
setId
(
$id
)
->
setPaymentMethod
(
$stripeIntent
->
payment_method
);
return
$
stripeIntent
->
id
;
return
$
intent
;
}
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
Core/Payments/Stripe/Intents/PaymentIntent.php
0 → 100644
View file @
c2099aa6
<?php
/**
* Stripe Payment Intent
*/
namespace
Minds\Core\Payments\Stripe\Intents
;
use
Minds\Traits\MagicAttributes
;
class
PaymentIntent
extends
Intent
{
use
MagicAttributes
;
/** @var int $amount */
private
$amount
=
0
;
/** @var int $quantity */
private
$quantity
=
1
;
/** @var string $currency */
private
$currency
=
'usd'
;
/** @var boolean $confirm */
private
$confirm
=
false
;
/** @var boolean $offSession */
private
$offSession
=
false
;
/** @var int $serviceFeePct */
private
$serviceFeePct
=
0
;
/**
* Return the service
* @return int
*/
public
function
getServiceFee
()
:
int
{
return
$this
->
amount
*
(
$this
->
serviceFeePct
/
100
);
}
/**
* Expose to the public apis
* @param array $extend
* @return array
*/
public
function
export
(
$extend
=
[])
{
return
[
];
}
}
This diff is collapsed.
Click to expand it.
Core/Payments/Stripe/Intents/SetupIntent.php
0 → 100644
View file @
c2099aa6
<?php
/**
* Stripe Payment Intent
*/
namespace
Minds\Core\Payments\Stripe\Intents
;
use
Minds\Traits\MagicAttributes
;
class
SetupIntent
extends
Intent
{
use
MagicAttributes
;
/**
* Expose to the public apis
* @param array $extend
* @return array
*/
public
function
export
(
$extend
=
[])
{
return
parent
::
export
(
$extend
);
}
}
This diff is collapsed.
Click to expand it.
Core/Payments/Stripe/PaymentMethods/Manager.php
0 → 100644
View file @
c2099aa6
<?php
namespace
Minds\Core\Payments\Stripe\PaymentMethods
;
use
Minds\Common\Repository\Response
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Payments\Stripe\Customers\Manager
as
CustomersManager
;
use
Minds\Core\Payments\Stripe\Customers\Customer
;
use
Minds\Core\Payments\Stripe\Instances\PaymentMethodInstance
;
class
Manager
{
/** @var Lookup $lookup */
private
$lookup
;
/** @var CustomersManager $customersManager */
private
$customersManager
;
/** @var PaymentMethodInstance $paymentMethodInstance */
private
$paymentMethodInstance
;
public
function
__construct
(
$lookup
=
null
,
$customersManager
=
null
,
$paymentMethodInstance
=
null
)
{
$this
->
lookup
=
$lookup
?:
Di
::
_
()
->
get
(
'Database\Cassandra\Lookup'
);
$this
->
customersManager
=
$customersManager
??
new
CustomersManager
;
$this
->
paymentMethodInstance
=
$paymentMethodInstance
??
new
PaymentMethodInstance
();
}
/**
* Return a list of payment method
* @param array $opts
* @return Response
*/
public
function
getList
(
array
$opts
=
[])
:
Response
{
if
(
!
$opts
[
'user_guid'
])
{
throw
new
\Exception
(
'User_guid not specified'
);
}
$customer
=
$this
->
customersManager
->
getFromUserGuid
(
$opts
[
'user_guid'
]);
$stripePaymentMethods
=
$this
->
paymentMethodInstance
->
all
([
'customer'
=>
$customer
->
getId
(),
'type'
=>
'card'
,
]);
$response
=
new
Response
();
foreach
(
$stripePaymentMethods
->
data
as
$stripePaymentMethod
)
{
$paymentMethod
=
new
PaymentMethod
();
$paymentMethod
->
setId
(
$stripePaymentMethod
->
id
)
->
setCardBrand
(
$stripePaymentMethod
->
card
->
brand
)
->
setCardCountry
(
$stripePaymentMethod
->
card
->
country
)
->
setCardExpires
(
$stripePaymentMethod
->
card
->
exp_month
.
'/'
.
$stripePaymentMethod
->
card
->
exp_year
)
->
setCardLast4
(
$stripePaymentMethod
->
card
->
last4
);
$response
[]
=
$paymentMethod
;
}
return
$response
;
}
/**
* Add a payment method to stripe
* @param Customer $customer
* @return boolean
*/
public
function
add
(
PaymentMethod
$paymentMethod
)
:
PaymentMethod
{
if
(
$paymentMethod
->
getCustomerId
())
{
$stripePaymentMethod
=
$this
->
paymentMethodInstance
->
retrieve
(
$paymentMethod
->
getId
());
$stripePaymentMethod
->
attach
([
'customer'
=>
$paymentMethod
->
getCustomerId
()
]);
}
else
{
$customer
=
new
Customer
();
$customer
->
setPaymentMethod
(
$paymentMethod
->
getId
())
->
setUserGuid
(
$paymentMethod
->
getUserGuid
());
$customer
=
$this
->
customersManager
->
add
(
$customer
);
$paymentMethod
->
setCustomerId
(
$customer
->
getId
());
}
return
$paymentMethod
;
}
/**
* Delete a payment method
* @param string $id
* @return bool
*/
public
function
delete
(
$id
)
:
bool
{
$stripePaymentMethod
=
$this
->
paymentMethodInstance
->
retrieve
(
$id
);
return
(
bool
)
$stripePaymentMethod
->
detach
();
}
}
This diff is collapsed.
Click to expand it.
Core/Payments/Stripe/PaymentMethods/PaymentMethod.php
0 → 100644
View file @
c2099aa6
<?php
/**
* Stripe PaymentMethod
*/
namespace
Minds\Core\Payments\Stripe\PaymentMethods
;
use
Minds\Traits\MagicAttributes
;
class
PaymentMethod
{
use
MagicAttributes
;
/** @var string $id */
private
$id
;
/** @var string $customerId */
private
$customerId
;
/** @var string $userGuid */
private
$userGuid
;
/** @var string $cardBrand */
private
$cardBrand
;
/** @var string $cardExpires */
private
$cardExpires
;
/** @var string $cardCountry */
private
$cardCountry
;
/** @var int $cardLast4 */
private
$cardLast4
;
/**
* Expose to the public apis
* @param array $extend
* @return array
*/
public
function
export
(
$extend
=
[])
{
return
[
'id'
=>
$this
->
id
,
'user_guid'
=>
(
string
)
$this
->
userGuid
,
'user'
=>
$this
->
user
?
$this
->
user
->
export
()
:
null
,
'card_brand'
=>
$this
->
cardBrand
,
'card_country'
=>
$this
->
cardCountry
,
'card_expires'
=>
$this
->
cardExpires
,
'card_last4'
=>
$this
->
cardLast4
,
];
}
}
This diff is collapsed.
Click to expand it.
Core/Payments/Stripe/Stripe.php
View file @
c2099aa6
...
...
@@ -321,7 +321,7 @@ class Stripe implements SubscriptionPaymentServiceInterface
);
$params
=
[
'type'
=>
'
charge
'
,
'type'
=>
'
payment
'
,
'limit'
=>
$hasFilter
?
100
:
(
int
)
$options
[
$limit
]
];
...
...
@@ -552,7 +552,7 @@ class Stripe implements SubscriptionPaymentServiceInterface
}
catch
(
\Exception
$e
)
{
return
false
;
}
$customer
->
setPaymentMethods
(
$result
->
sources
->
data
);
return
$customer
;
...
...
This diff is collapsed.
Click to expand it.
Core/Wire/Delegates/CacheDelegate.php
0 → 100644
View file @
c2099aa6
<?php
namespace
Minds\Core\Wire\Delegates
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Wire\Counter
;
use
Minds\Core\Wire\Wire
;
class
CacheDelegate
{
/** @var Data\cache\Redis */
private
$cache
;
public
function
__construct
(
$cache
=
null
)
{
$this
->
cache
=
$cache
?:
Di
::
_
()
->
get
(
'Cache'
);
}
/**
* OnAdd, clear the cache
* @param Wire $wire
* @return void
*/
public
function
onAdd
(
Wire
$wire
)
:
void
{
$this
->
cache
->
destroy
(
Counter
::
getIndexName
(
$wire
->
getEntity
()
->
guid
,
null
,
'tokens'
,
null
,
true
));
}
}
This diff is collapsed.
Click to expand it.
Core/Wire/Delegates/NotificationDelegate.php
0 → 100644
View file @
c2099aa6
<?php
namespace
Minds\Core\Wire\Delegates
;
use
Minds\Core\Wire\Wire
;
use
Minds\Core\Queue
;
class
NotificationDelegate
{
/** @var Queue\Client $queue */
protected
$queue
;
public
function
__construct
(
$queue
=
null
)
{
$this
->
queue
=
$queue
?:
Queue\Client
::
build
();
}
/**
* OnAdd, send a notification
* @param Wire $wire
* @return void
*/
public
function
onAdd
(
Wire
$wire
)
:
void
{
$this
->
queue
->
setQueue
(
'WireNotification'
)
->
send
(
[
'wire'
=>
serialize
(
$wire
),
'entity'
=>
serialize
(
$wire
->
getEntity
()),
]
);
}
}
This diff is collapsed.
Click to expand it.
Core/Wire/Delegates/RecurringDelegate.php
0 → 100644
View file @
c2099aa6
<?php
namespace
Minds\Core\Wire\Delegates
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Wire\Wire
;
use
Minds\Core\Payments\Subscriptions\Subscription
;
class
RecurringDelegate
{
/** @var $subscriptionsManager */
private
$subscriptionsManager
;
public
function
__construct
(
$subscriptionsManager
=
null
)
{
$this
->
subscriptionsManager
=
$subscriptionsManager
??
Di
::
_
()
->
get
(
'Payments\Subscriptions\Manager'
);
}
/**
* OnAdd, make subscription
* @param Wire $wire
* @return void
*/
public
function
onAdd
(
Wire
$wire
)
:
void
{
$urn
=
"urn:subscription:"
.
implode
(
'-'
,
[
$wire
->
getAddress
(),
//offchain or onchain wallet or usd
$wire
->
getSender
()
->
getGuid
(),
$wire
->
getReceiver
()
->
getGuid
(),
]);
$subscription
=
(
new
Subscription
())
->
setId
(
$urn
)
->
setPlanId
(
'wire'
)
->
setPaymentMethod
(
$wire
->
getMethod
())
->
setAmount
(
$wire
->
getAmount
())
->
setUser
(
$wire
->
getSender
())
->
setEntity
(
$wire
->
getReceiver
());
$this
->
subscriptionsManager
->
setSubscription
(
$subscription
);
$this
->
subscriptionsManager
->
create
();
}
}
This diff is collapsed.
Click to expand it.
Core/Wire/Manager.php
View file @
c2099aa6
...
...
@@ -17,18 +17,14 @@ use Minds\Core\Wire\Subscriptions\Manager as SubscriptionsManager;
use
Minds\Common\Urn
;
use
Minds\Entities
;
use
Minds\Entities\User
;
use
Minds\Core\Payments\Stripe\Intents\PaymentIntent
;
use
Minds\Core\Payments\Stripe\Intents\Manager
as
StripeIntentsManager
;
class
Manager
{
/** @var Data\cache\Redis */
protected
$cache
;
/** @var Repository */
protected
$repository
;
/** @var SubscriptionsManager $subscriptionsManager */
protected
$subscriptionsManager
;
/** @var Core\Blockchain\Transactions\Manager */
protected
$txManager
;
...
...
@@ -56,9 +52,6 @@ class Manager
/** @var Core\Config */
protected
$config
;
/** @var Core\Queue\Client */
protected
$queue
;
/** @var Core\Blockchain\Services\Ethereum */
protected
$client
;
...
...
@@ -67,44 +60,53 @@ class Manager
/** @var Core\Blockchain\Wallets\OffChain\Cap $cap */
protected
$cap
;
/** @var Core\Events\EventsDispatcher */
protected
$dispatcher
;
/** @var Delegates\Plus $plusDelegate */
protected
$plusDelegate
;
/** @var Delegates\RecurringDelegate $recurringDelegate */
protected
$recurringDelegate
;
/** @var Delegates\NotificationDelegate $notificationDelegate */
protected
$notificationDelegate
;
/** @var Delegates\CacheDelete $cacheDelegate */
protected
$cacheDelegate
;
/** @var Core\Blockchain\Wallets\OffChain\Transactions */
protected
$offchainTxs
;
/** @var StripeIntentsManager $stripeIntentsManager */
protected
$stripeIntentsManager
;
public
function
__construct
(
$cache
=
null
,
$repository
=
null
,
$subscriptionsManager
=
null
,
$txManager
=
null
,
$txRepo
=
null
,
$config
=
null
,
$queue
=
null
,
$client
=
null
,
$token
=
null
,
$cap
=
null
,
$dispatcher
=
null
,
$plusDelegate
=
null
,
$offchainTxs
=
null
$recurringDelegate
=
null
,
$notificationDelegate
=
null
,
$cacheDelegate
=
null
,
$offchainTxs
=
null
,
$stripeIntentsManager
=
null
)
{
$this
->
cache
=
$cache
?:
Di
::
_
()
->
get
(
'Cache'
);
$this
->
repository
=
$repository
?:
Di
::
_
()
->
get
(
'Wire\Repository'
);
$this
->
subscriptionsManager
=
$subscriptionsManager
?:
Di
::
_
()
->
get
(
'Wire\Subscriptions\Manager'
);
$this
->
txManager
=
$txManager
?:
Di
::
_
()
->
get
(
'Blockchain\Transactions\Manager'
);
$this
->
txRepo
=
$txRepo
?:
Di
::
_
()
->
get
(
'Blockchain\Transactions\Repository'
);
$this
->
config
=
$config
?:
Di
::
_
()
->
get
(
'Config'
);
$this
->
queue
=
$queue
?:
Core\Queue\Client
::
build
();
$this
->
client
=
$client
?:
Di
::
_
()
->
get
(
'Blockchain\Services\Ethereum'
);
$this
->
token
=
$token
?:
Di
::
_
()
->
get
(
'Blockchain\Token'
);
$this
->
cap
=
$cap
?:
Di
::
_
()
->
get
(
'Blockchain\Wallets\OffChain\Cap'
);
$this
->
dispatcher
=
$dispatcher
?:
Di
::
_
()
->
get
(
'EventsDispatcher'
);
$this
->
plusDelegate
=
$plusDelegate
?:
new
Delegates\Plus
();
$this
->
recurringDelegate
=
$recurringDelegate
?:
new
Delegates\RecurringDelegate
();
$this
->
notificationDelegate
=
$notificationDelegate
?:
new
Delegates\NotificationDelegate
();
$this
->
cacheDelegate
=
$cacheDelegate
?:
new
Delegates\CacheDelegate
();
$this
->
offchainTxs
=
$offchainTxs
?:
new
Core\Blockchain\Wallets\OffChain\Transactions
();
$this
->
stripeIntentsManager
=
$stripeIntentsManager
??
Di
::
_
()
->
get
(
'Stripe\Intents\Manager'
);
}
/**
...
...
@@ -183,13 +185,6 @@ class Manager
throw
new
WalletNotSetupException
();
}
if
(
$this
->
recurring
)
{
$this
->
subscriptionsManager
->
setAmount
(
$this
->
amount
)
->
setSender
(
$this
->
sender
)
->
setReceiver
(
$this
->
receiver
);
}
$wire
=
new
Wire
();
$wire
->
setSender
(
$this
->
sender
)
...
...
@@ -220,11 +215,7 @@ class Manager
]);
$this
->
txManager
->
add
(
$transaction
);
if
(
$this
->
recurring
)
{
$this
->
subscriptionsManager
->
setAddress
(
$this
->
payload
[
'address'
])
->
create
();
}
$wire
->
setAddress
(
$this
->
payload
[
'address'
]);
break
;
case
'offchain'
:
...
...
@@ -255,22 +246,17 @@ class Manager
// Save the wire to the Repository
$this
->
repository
->
add
(
$wire
);
$wire
->
setAddress
(
'offchain'
);
// Notify plus
$this
->
plusDelegate
->
onWire
(
$wire
,
'offchain'
);
// Send notification
$this
->
sendNotification
(
$wire
);
$this
->
notificationDelegate
->
onAdd
(
$wire
);
// Clear caches
$this
->
clearWireCache
(
$wire
);
// Register the next subscription, if needed
if
(
$this
->
recurring
)
{
$this
->
subscriptionsManager
->
setAddress
(
'offchain'
)
->
create
();
}
$this
->
cacheDelegate
->
onAdd
(
$wire
);
break
;
case
'erc20'
:
...
...
@@ -279,35 +265,37 @@ class Manager
case
'eth'
:
throw
new
\Exception
(
"Not implemented ETH yet"
);
break
;
case
'
money
'
:
$intent
=
new
Stripe
PaymentIntent
();
case
'
usd
'
:
$intent
=
new
PaymentIntent
();
$intent
->
setUserGuid
(
$this
->
sender
->
getGuid
())
->
setAmount
(
$this
->
amount
)
->
setDestination
(
$this
->
receiver
->
getStripeAccount
());
->
setPaymentMethod
(
$this
->
payload
[
'paymentMethodId'
])
->
setOffSession
(
true
)
->
setConfirm
(
true
)
->
setStripeAccountId
(
$this
->
receiver
->
getMerchant
()[
'id'
]);
// Charge stripe
$this
->
stripeManager
->
charge
(
$intent
);
// Register the next subscription, if needed
if
(
$this
->
recurring
)
{
$this
->
subscriptionsManager
->
setMethod
(
'money'
)
->
setAddress
(
'stripe'
)
->
create
();
}
$this
->
stripeIntentsManager
->
add
(
$intent
);
$wire
->
setAddress
(
'stripe'
)
->
setMethod
(
'usd'
);
// Save the wire to the Repository
$this
->
repository
->
add
(
$wire
);
// Send notification
$this
->
sendNotification
(
$wire
);
$this
->
notificationDelegate
->
onAdd
(
$wire
);
// Clear caches
$this
->
c
learWireCache
(
$wire
);
$this
->
c
acheDelegate
->
onAdd
(
$wire
);
break
;
}
if
(
$this
->
recurring
)
{
$this
->
recurringDelegate
->
onAdd
(
$wire
);
}
return
true
;
}
...
...
@@ -342,29 +330,12 @@ class Manager
$this
->
plusDelegate
->
onWire
(
$wire
,
$data
[
'receiver_address'
]);
$this
->
sendNotification
(
$wire
);
$this
->
notificationDelegate
->
onAdd
(
$wire
);
$this
->
c
learWireCache
(
$wire
);
$this
->
c
acheDelegate
->
onAdd
(
$wire
);
return
$success
;
}
/**
* @param Wire $wire
*/
protected
function
clearWireCache
(
Wire
$wire
)
{
$this
->
cache
->
destroy
(
Counter
::
getIndexName
(
$wire
->
getEntity
()
->
guid
,
null
,
'tokens'
,
null
,
true
));
}
protected
function
sendNotification
(
Wire
$wire
=
null
)
{
$this
->
queue
->
setQueue
(
'WireNotification'
)
->
send
(
[
'wire'
=>
serialize
(
$wire
),
'entity'
=>
serialize
(
$wire
->
getEntity
()),
]
);
}
}
This diff is collapsed.
Click to expand it.
Core/Wire/Wire.php
View file @
c2099aa6
...
...
@@ -29,9 +29,12 @@ class Wire
/** @var bool **/
private
$recurring
=
false
;
/** @var
method *
*/
/** @var
string $method
*/
private
$method
=
'tokens'
;
/** @var string $address */
private
$address
;
/** @var int $timestamp **/
private
$timestamp
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment