Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,28 +12,38 @@
|
||||
namespace IPS\nexus\Gateway\Stripe;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DomainException;
|
||||
use IPS\Db;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\CreditCard as CreditCardClass;
|
||||
use IPS\nexus\Customer\CreditCard as CustomerCardClass;
|
||||
use UnexpectedValueException;
|
||||
use function count;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stripe Stored Card
|
||||
*/
|
||||
class _CreditCard extends \IPS\nexus\Customer\CreditCard
|
||||
class CreditCard extends CustomerCardClass
|
||||
{
|
||||
/**
|
||||
* @brief Card
|
||||
*/
|
||||
protected $_card;
|
||||
protected ?CreditCardClass $_card = null;
|
||||
|
||||
/**
|
||||
* Get card
|
||||
*
|
||||
* @return \IPS\nexus\CreditCard
|
||||
* @return CreditCardClass
|
||||
*/
|
||||
public function get_card()
|
||||
public function get_card() : CreditCardClass
|
||||
{
|
||||
if ( !$this->_card )
|
||||
{
|
||||
@@ -41,33 +51,33 @@ class _CreditCard extends \IPS\nexus\Customer\CreditCard
|
||||
{
|
||||
$response = $this->method->api( "sources/{$this->data}", NULL, 'get' );
|
||||
|
||||
$this->_card = new \IPS\nexus\CreditCard;
|
||||
$this->_card = new CreditCardClass;
|
||||
$this->_card->lastFour = $response['card']['last4'];
|
||||
switch ( $response['card']['brand'] )
|
||||
{
|
||||
case 'Visa':
|
||||
case 'visa':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_VISA;
|
||||
$this->_card->type = CreditCardClass::TYPE_VISA;
|
||||
break;
|
||||
case 'American Express':
|
||||
case 'amex':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_AMERICAN_EXPRESS;
|
||||
$this->_card->type = CreditCardClass::TYPE_AMERICAN_EXPRESS;
|
||||
break;
|
||||
case 'mastercard':
|
||||
case 'MasterCard':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_MASTERCARD;
|
||||
$this->_card->type = CreditCardClass::TYPE_MASTERCARD;
|
||||
break;
|
||||
case 'Discover':
|
||||
case 'discover':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_DISCOVER;
|
||||
$this->_card->type = CreditCardClass::TYPE_DISCOVER;
|
||||
break;
|
||||
case 'JCB':
|
||||
case 'jcb':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_JCB;
|
||||
$this->_card->type = CreditCardClass::TYPE_JCB;
|
||||
break;
|
||||
case 'Diners Club':
|
||||
case 'diners':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_DINERS_CLUB;
|
||||
$this->_card->type = CreditCardClass::TYPE_DINERS_CLUB;
|
||||
break;
|
||||
}
|
||||
$this->_card->expMonth = $response['card']['exp_month'];
|
||||
@@ -77,33 +87,33 @@ class _CreditCard extends \IPS\nexus\Customer\CreditCard
|
||||
{
|
||||
$response = $this->method->api( "payment_methods/{$this->data}", NULL, 'get' );
|
||||
|
||||
$this->_card = new \IPS\nexus\CreditCard;
|
||||
$this->_card = new CreditCardClass;
|
||||
$this->_card->lastFour = $response['card']['last4'];
|
||||
switch ( $response['card']['brand'] )
|
||||
{
|
||||
case 'Visa':
|
||||
case 'visa':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_VISA;
|
||||
$this->_card->type = CreditCardClass::TYPE_VISA;
|
||||
break;
|
||||
case 'American Express':
|
||||
case 'amex':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_AMERICAN_EXPRESS;
|
||||
$this->_card->type = CreditCardClass::TYPE_AMERICAN_EXPRESS;
|
||||
break;
|
||||
case 'mastercard':
|
||||
case 'MasterCard':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_MASTERCARD;
|
||||
$this->_card->type = CreditCardClass::TYPE_MASTERCARD;
|
||||
break;
|
||||
case 'Discover':
|
||||
case 'discover':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_DISCOVER;
|
||||
$this->_card->type = CreditCardClass::TYPE_DISCOVER;
|
||||
break;
|
||||
case 'JCB':
|
||||
case 'jcb':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_JCB;
|
||||
$this->_card->type = CreditCardClass::TYPE_JCB;
|
||||
break;
|
||||
case 'Diners Club':
|
||||
case 'diners':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_DINERS_CLUB;
|
||||
$this->_card->type = CreditCardClass::TYPE_DINERS_CLUB;
|
||||
break;
|
||||
}
|
||||
$this->_card->expMonth = $response['card']['exp_month'];
|
||||
@@ -114,38 +124,38 @@ class _CreditCard extends \IPS\nexus\Customer\CreditCard
|
||||
$profiles = $this->member->cm_profiles;
|
||||
if ( !isset( $profiles[ $this->method->id ] ) )
|
||||
{
|
||||
throw new \UnexpectedValueException;
|
||||
throw new UnexpectedValueException;
|
||||
}
|
||||
|
||||
$response = $this->method->api( "customers/{$profiles[ $this->method->id ]}/cards/{$this->data}", NULL, 'get' );
|
||||
|
||||
$this->_card = new \IPS\nexus\CreditCard;
|
||||
$this->_card = new CreditCardClass;
|
||||
$this->_card->lastFour = $response['last4'];
|
||||
switch ( $response['type'] )
|
||||
{
|
||||
case 'Visa':
|
||||
case 'visa':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_VISA;
|
||||
$this->_card->type = CreditCardClass::TYPE_VISA;
|
||||
break;
|
||||
case 'American Express':
|
||||
case 'amex':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_AMERICAN_EXPRESS;
|
||||
$this->_card->type = CreditCardClass::TYPE_AMERICAN_EXPRESS;
|
||||
break;
|
||||
case 'mastercard':
|
||||
case 'MasterCard':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_MASTERCARD;
|
||||
$this->_card->type = CreditCardClass::TYPE_MASTERCARD;
|
||||
break;
|
||||
case 'Discover':
|
||||
case 'discover':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_DISCOVER;
|
||||
$this->_card->type = CreditCardClass::TYPE_DISCOVER;
|
||||
break;
|
||||
case 'JCB':
|
||||
case 'jcb':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_JCB;
|
||||
$this->_card->type = CreditCardClass::TYPE_JCB;
|
||||
break;
|
||||
case 'Diners Club':
|
||||
case 'diners':
|
||||
$this->_card->type = \IPS\nexus\CreditCard::TYPE_DINERS_CLUB;
|
||||
$this->_card->type = CreditCardClass::TYPE_DINERS_CLUB;
|
||||
break;
|
||||
}
|
||||
$this->_card->expMonth = $response['exp_month'];
|
||||
@@ -158,10 +168,10 @@ class _CreditCard extends \IPS\nexus\Customer\CreditCard
|
||||
/**
|
||||
* Set card
|
||||
*
|
||||
* @param \IPS\nexus\CreditCard $card The card
|
||||
* @param CustomerCardClass $card The card
|
||||
* @return void
|
||||
*/
|
||||
public function set_card( \IPS\nexus\CreditCard $card )
|
||||
public function set_card( CustomerCardClass $card ) : void
|
||||
{
|
||||
/* Create a customer object if we don't have one */
|
||||
$profiles = $this->member->cm_profiles;
|
||||
@@ -183,8 +193,8 @@ class _CreditCard extends \IPS\nexus\Customer\CreditCard
|
||||
$response = $this->method->api( "payment_methods/{$card->token}", NULL, 'get' );
|
||||
|
||||
/* Check it doesn't already exist */
|
||||
$otherCards = \IPS\Db::i()->select( 'card_data', 'nexus_customer_cards', array( 'card_member=? AND card_method=?', $this->member->member_id, $this->method->id ) );
|
||||
if ( \count( $otherCards ) )
|
||||
$otherCards = Db::i()->select( 'card_data', 'nexus_customer_cards', array( 'card_member=? AND card_method=?', $this->member->member_id, $this->method->id ) );
|
||||
if ( count( $otherCards ) )
|
||||
{
|
||||
if ( isset( $response['card']['fingerprint'] ) )
|
||||
{
|
||||
@@ -209,10 +219,10 @@ class _CreditCard extends \IPS\nexus\Customer\CreditCard
|
||||
|
||||
if ( isset( $otherCardData['fingerprint'] ) and $otherCardData['fingerprint'] === $response['card']['fingerprint'] )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack('card_is_duplicate') );
|
||||
throw new DomainException( Member::loggedIn()->language()->addToStack('card_is_duplicate') );
|
||||
}
|
||||
}
|
||||
catch ( \IPS\nexus\Gateway\Stripe\Exception $e ) { }
|
||||
catch (Exception ) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,9 +238,9 @@ class _CreditCard extends \IPS\nexus\Customer\CreditCard
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
$profiles = $this->member->cm_profiles;
|
||||
try
|
||||
@@ -248,7 +258,9 @@ class _CreditCard extends \IPS\nexus\Customer\CreditCard
|
||||
$this->method->api( "customers/{$profiles[ $this->method->id ]}/cards/{$this->data}", NULL, 'delete' );
|
||||
}
|
||||
}
|
||||
catch ( \IPS\nexus\Gateway\Stripe\Exception $e ) { }
|
||||
return parent::delete();
|
||||
|
||||
catch ( Exception ) { }
|
||||
|
||||
parent::delete();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user