wip
This commit is contained in:
@ -36,9 +36,6 @@ class MembershipProducts extends DatabaseModel {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
|
||||
|
||||
if ( ! self::$loaded ) {
|
||||
$api_key = Config::getValue( 'memberships/stripeSecret' );
|
||||
if ( $api_key == 'sk_xxxxxxxxxxxxxxx' || empty($api_key) ) {
|
||||
@ -48,8 +45,6 @@ class MembershipProducts extends DatabaseModel {
|
||||
}
|
||||
self::$loaded = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function create( $name, $description, $monthly_price, $yearly_price ) {
|
||||
@ -88,12 +83,14 @@ class MembershipProducts extends DatabaseModel {
|
||||
]);
|
||||
return $product;
|
||||
}
|
||||
|
||||
public function createStripePrices( $product, $monthly_price, $yearly_price ) {
|
||||
$out = [];
|
||||
$out['monthly'] = $this->createStripeMonthlyPrice( $product, $monthly_price );
|
||||
$out['yearly'] = $this->createStripeYearlyPrice( $product, $yearly_price );
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function createStripeMonthlyPrice( $product, $monthly_price ) {
|
||||
if ( empty( self::$stripe ) ) {
|
||||
return false;
|
||||
@ -106,6 +103,7 @@ class MembershipProducts extends DatabaseModel {
|
||||
'lookup_key' => 'membership-monthly',
|
||||
]);
|
||||
}
|
||||
|
||||
public function createStripeYearlyPrice( $product, $yearly_price ) {
|
||||
if ( empty( self::$stripe ) ) {
|
||||
return false;
|
||||
@ -173,6 +171,7 @@ class MembershipProducts extends DatabaseModel {
|
||||
);
|
||||
return $this->createStripeYearlyPrice( $product, $yearly_price );
|
||||
}
|
||||
|
||||
public function updateStripeMonthlyPrice( $product, $monthly_price ) {
|
||||
$stripe->prices->update(
|
||||
$monthly->id,
|
||||
@ -206,10 +205,18 @@ class MembershipProducts extends DatabaseModel {
|
||||
|
||||
public function findByPriceID( $d ) {
|
||||
$data = self::$db->get( $this->tableName, [ 'stripe_price_monthly', '=', $d, 'OR', 'stripe_price_yearly', '=', $d ] );
|
||||
|
||||
if ( ! $data->count() ) {
|
||||
return false;
|
||||
}
|
||||
return $data->first();
|
||||
}
|
||||
|
||||
public function mainProduct() {
|
||||
$data = self::$db->get( $this->tableName, '*' );
|
||||
if ( ! $data->count() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->filter( $data->first() );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user