Version 5.0.6
This commit is contained in:
1 parent
a3a4a9ccbd
commit
b89858b2ff
1214 files changed
+92828
-14859
No files matched your search
@@ -128,6 +128,11 @@ abstract class Gateway extends Model
|
||||
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
|
||||
*/
|
||||
public static ?string $titleLangPrefix = 'nexus_paymethod_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Enabled/Disabled Column
|
||||
*/
|
||||
public static ?string $databaseColumnEnabledDisabled = 'active';
|
||||
|
||||
/**
|
||||
* Construct ActiveRecord from database row
|
||||
@@ -176,28 +181,6 @@ abstract class Gateway extends Model
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get whether or not this node is enabled
|
||||
*
|
||||
* @note Return value NULL indicates the node cannot be enabled/disabled
|
||||
* @return bool|null
|
||||
*/
|
||||
protected function get__enabled(): ?bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Set whether or not this node is enabled
|
||||
*
|
||||
* @param bool|int $enabled Whether to set it enabled or disabled
|
||||
* @return void
|
||||
*/
|
||||
protected function set__enabled( bool|int $enabled ) : void
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
* @code
|
||||
@@ -490,6 +473,12 @@ abstract class Gateway extends Model
|
||||
*/
|
||||
public function checkValidity(Money $amount, ?GeoLocation $billingAddress = NULL, ?Customer $customer = NULL, array $recurrings = array() ) : bool
|
||||
{
|
||||
/* If the gateway is disabled, skip it */
|
||||
if( !$this->active )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $this->countries !== '*' )
|
||||
{
|
||||
if ( $billingAddress )
|
||||
|
||||
@@ -505,7 +505,7 @@ class PayPal extends Gateway
|
||||
/* Send the request */
|
||||
try
|
||||
{
|
||||
$response = $this->api( 'checkout/orders', [
|
||||
$intent = [
|
||||
'intent' => 'AUTHORIZE',
|
||||
'purchase_units' => $this->_getPurchaseUnits( $transaction ),
|
||||
'payment_source' => [
|
||||
@@ -515,16 +515,23 @@ class PayPal extends Gateway
|
||||
'cancel_url' => (string)$transaction->invoice->checkoutUrl(),
|
||||
],
|
||||
'email_address' => $transaction->member->email,
|
||||
'name' => [
|
||||
'given_name' => $this->_getFirstName( $transaction ),
|
||||
'surname' => $this->_getLastName( $transaction )
|
||||
],
|
||||
'address' => ( $transaction->invoice->billaddress instanceof GeoLocation ) ? $this->_getAddress( $transaction->invoice->billaddress, $transaction->member ) : null,
|
||||
]
|
||||
]
|
||||
], 'POST', true, null, md5( $transaction->invoice->checkoutUrl() . ';' . $transaction->id ), 2 );
|
||||
];
|
||||
|
||||
try
|
||||
{
|
||||
$intent['payment_source']['paypal']['name'] = [
|
||||
'given_name' => $this->_getFirstName( $transaction ),
|
||||
'surname' => $this->_getLastName( $transaction )
|
||||
];
|
||||
}
|
||||
catch( UnexpectedValueException ){}
|
||||
|
||||
$response = $this->api( 'checkout/orders', $intent, 'POST', true, null, md5( $transaction->invoice->checkoutUrl() . ';' . $transaction->id ), 2 );
|
||||
}
|
||||
catch(PayPal\Exception $e )
|
||||
catch( PayPal\Exception $e )
|
||||
{
|
||||
$this->processException( $transaction, $e );
|
||||
throw $e;
|
||||
@@ -645,14 +652,10 @@ class PayPal extends Gateway
|
||||
$plan = $this->api( 'billing/plans', $planDetails );
|
||||
|
||||
/* Create a subscription */
|
||||
$subscription = $this->api( 'billing/subscriptions', array(
|
||||
$planData = array(
|
||||
'plan_id' => $plan['id'],
|
||||
'quantity' => '1',
|
||||
'subscriber' => array(
|
||||
'name' => array(
|
||||
'given_name' => $this->_getFirstName( $transaction ),
|
||||
'surname' => $this->_getLastName( $transaction )
|
||||
),
|
||||
'email_address' => $transaction->member->email,
|
||||
),
|
||||
'application_context' => array(
|
||||
@@ -668,7 +671,21 @@ class PayPal extends Gateway
|
||||
'cancel_url' => (string) $transaction->invoice->checkoutUrl(),
|
||||
'return_url' => Settings::i()->base_url . 'applications/nexus/interface/gateways/paypal.php?subscription=1&nexusTransactionId=' . $transaction->id,
|
||||
)
|
||||
) );
|
||||
);
|
||||
|
||||
if( $transaction->invoice->hasItemsRequiringBillingAddress() )
|
||||
{
|
||||
try
|
||||
{
|
||||
$planData['subscriber']['name'] = array(
|
||||
'given_name' => $this->_getFirstName( $transaction ),
|
||||
'surname' => $this->_getLastName( $transaction )
|
||||
);
|
||||
}
|
||||
catch( UnexpectedValueException ){}
|
||||
}
|
||||
|
||||
$subscription = $this->api( 'billing/subscriptions', $planData );
|
||||
|
||||
/* Redirect */
|
||||
foreach ( $subscription['links'] as $link )
|
||||
@@ -1250,27 +1267,43 @@ class PayPal extends Gateway
|
||||
/* Return */
|
||||
return $address;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get first name for PayPal
|
||||
*
|
||||
* @param Transaction $transaction Transaction
|
||||
* @return string
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
protected function _getFirstName( Transaction $transaction ) : string
|
||||
{
|
||||
return $transaction->invoice->member->member_id ? $transaction->invoice->member->cm_first_name : $transaction->invoice->guest_data['member']['cm_first_name'];
|
||||
$name = $transaction->invoice->member->member_id ? $transaction->invoice->member->cm_first_name : $transaction->invoice->guest_data['member']['cm_first_name'];
|
||||
|
||||
if( empty( $name ) )
|
||||
{
|
||||
throw new UnexpectedValueException;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get last name for PayPal
|
||||
*
|
||||
* @param Transaction $transaction Transaction
|
||||
* @return string
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
protected function _getLastName( Transaction $transaction ) : string
|
||||
{
|
||||
return $transaction->invoice->member->member_id ? $transaction->invoice->member->cm_last_name : $transaction->invoice->guest_data['member']['cm_last_name'];
|
||||
$name = $transaction->invoice->member->member_id ? $transaction->invoice->member->cm_last_name : $transaction->invoice->guest_data['member']['cm_last_name'];
|
||||
|
||||
if( empty( $name ) )
|
||||
{
|
||||
throw new UnexpectedValueException;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,6 +55,7 @@ use function in_array;
|
||||
use function intval;
|
||||
use function is_numeric;
|
||||
use function is_string;
|
||||
use function str_starts_with;
|
||||
use function strlen;
|
||||
use const IPS\CIC;
|
||||
use const IPS\LONG_REQUEST_TIMEOUT;
|
||||
@@ -89,6 +90,19 @@ class Stripe extends Gateway
|
||||
{
|
||||
$settings = json_decode( $this->settings, TRUE );
|
||||
|
||||
/* Check if we are using test or live keys */
|
||||
if( \IPS\NEXUS_TEST_GATEWAYS )
|
||||
{
|
||||
if( !str_starts_with( $settings['secret_key'], 'sk_test_' ) or !str_starts_with( $settings['publishable_key'], 'pk_test_' ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
elseif( !str_starts_with( $settings['secret_key'], 'sk_live_' ) or !str_starts_with( $settings['publishable_key'], 'pk_live_' ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Stripe has a minimum transaction fee. This is based on the businesses currency, but as we don't know what the transaction rate is
|
||||
we'll do this check only in the transactions we know - anything else will be rejected when the user tries to pay */
|
||||
switch ( $amount->currency )
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace IPS\nexus\Gateway;
|
||||
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use IPS\GeoLocation;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\nexus\Customer;
|
||||
use IPS\nexus\Gateway;
|
||||
@@ -41,6 +42,25 @@ class Test extends Gateway
|
||||
const SUPPORTS_PARTIAL_REFUNDS = TRUE;
|
||||
|
||||
/* !Payment Gateway */
|
||||
|
||||
/**
|
||||
* Check the gateway can process this...
|
||||
*
|
||||
* @param $amount Money The amount
|
||||
* @param $billingAddress GeoLocation|NULL The billing address, which may be NULL if one if not provided
|
||||
* @param $customer Customer|null The customer (Default NULL value is for backwards compatibility - it should always be provided.)
|
||||
* @param array $recurrings Details about recurring costs
|
||||
* @return bool
|
||||
*/
|
||||
public function checkValidity( Money $amount, ?GeoLocation $billingAddress = NULL, ?Customer $customer = NULL, array $recurrings = array() ) : bool
|
||||
{
|
||||
if( !NEXUS_TEST_GATEWAYS )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return parent::checkValidity( $amount, $billingAddress, $customer, $recurrings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Payment Screen Fields
|
||||
|
||||
Reference in new issue
Block a user