Version 4.2.0

This commit is contained in:
Neo committed 2025-12-19 05:44:59 -08:00
1 parent 0dc2aee5ed
commit 96997ddd8e
2074 files changed
+125454 -55780

No files matched your search

@@ -1,13 +1,12 @@
<?php
/**
* @brief Stripe Gateway
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Nexus
* @since 13 Mar 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\Gateway;
@@ -104,13 +103,13 @@ class _Stripe extends \IPS\nexus\Gateway
/**
* Payment Screen Fields
*
* @param \IPS\nexus\Invoice $invoice Invoice
* @param \IPS\nexus\Money $amount The amount to pay now
* @param \IPS\Member $member The member the payment screen is for (if in the ACP charging to a member's card) or NULL for currently logged in member
* @param array $recurrings Details about recurring costs
* @param \IPS\nexus\Invoice $invoice Invoice
* @param \IPS\nexus\Money $amount The amount to pay now
* @param \IPS\nexus\Customer $member The member the payment screen is for (if in the ACP charging to a member's card) or NULL for currently logged in member
* @param array $recurrings Details about recurring costs
* @return array
*/
public function paymentScreen( \IPS\nexus\Invoice $invoice, \IPS\nexus\Money $amount, \IPS\Member $member = NULL, $recurrings = array() )
public function paymentScreen( \IPS\nexus\Invoice $invoice, \IPS\nexus\Money $amount, \IPS\nexus\Customer $member = NULL, $recurrings = array() )
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'global_gateways.js', 'nexus', 'global' ) );
@@ -134,11 +133,18 @@ class _Stripe extends \IPS\nexus\Gateway
'data-controller' => 'nexus.global.gateways.stripe',
'data-id' => $this->id,
'class' => 'ipsHide',
'data-key' => $settings['publishable_key']
'data-key' => $settings['publishable_key'],
'data-name' => $member ? $member->cm_name : $invoice->member->cm_name,
'data-address1' => ( $invoice->billaddress and isset( $invoice->billaddress->addressLines[0] ) ) ? $invoice->billaddress->addressLines[0] : NULL,
'data-address2' => ( $invoice->billaddress and isset( $invoice->billaddress->addressLines[1] ) ) ? $invoice->billaddress->addressLines[1] : NULL,
'data-city' => $invoice->billaddress ? $invoice->billaddress->city : NULL,
'data-state' => $invoice->billaddress ? $invoice->billaddress->region : NULL,
'data-zip' => $invoice->billaddress ? $invoice->billaddress->postalCode : NULL,
'data-country' => $invoice->billaddress ? $invoice->billaddress->country : NULL,
),
'jsRequired' => TRUE,
'names' => FALSE,
'save' => ( $settings['cards'] and \IPS\Member::loggedIn()->member_id ) ? $this : NULL,
'save' => ( $settings['cards'] ) ? $this : NULL,
'member' => $member,
) ) );
}
@@ -163,10 +169,32 @@ class _Stripe extends \IPS\nexus\Gateway
/* Build data */
$data = array(
'amount' => static::_amountAsCents( $transaction->amount ),
'currency' => $transaction->amount->currency,
'capture' => 'false'
'amount' => static::_amountAsCents( $transaction->amount ),
'currency' => $transaction->amount->currency,
'capture' => 'false',
'description' => $transaction->invoice->title,
'metadata' => array(
"Transaction ID" => $transaction->id,
"Invoice ID" => $transaction->invoice->id,
"Customer ID" => $transaction->member->id,
"Customer Email" => $transaction->member->email,
),
);
if ( $transaction->invoice->shipaddress )
{
$data['shipping'] = array(
'address' => array(
'city' => $transaction->invoice->shipaddress->city,
'country' => $transaction->invoice->shipaddress->country,
'line1' => isset( $transaction->invoice->shipaddress->addressLines[0] ) ? $transaction->invoice->shipaddress->addressLines[0] : NULL,
'line2' => isset( $transaction->invoice->shipaddress->addressLines[1] ) ? $transaction->invoice->shipaddress->addressLines[1] : NULL,
'postal_code' => $transaction->invoice->shipaddress->postalCode,
'state' => $transaction->invoice->shipaddress->region,
),
'name' => $transaction->invoice->member->cm_name,
'phone' => isset( $transaction->invoice->member->cm_phone ) ? $transaction->invoice->member->cm_phone : NULL
);
}
$card = $values[ $this->id . '_card' ];
/* Stored Card */
@@ -183,13 +211,20 @@ class _Stripe extends \IPS\nexus\Gateway
/* Are we saving it? */
$settings = json_decode( $this->settings, TRUE );
if ( $settings['cards'] and $card->save )
{
{
if ( !$transaction->member->member_id )
{
$transaction->member = $transaction->invoice->createAccountForGuest();
\IPS\Session::i()->setMember( $transaction->member );
\IPS\Member\Device::loadOrCreate( $transaction->member, FALSE )->updateAfterAuthentication( NULL );
}
$storedCard = new \IPS\nexus\Gateway\Stripe\CreditCard;
$storedCard->member = $transaction->member;
$storedCard->method = $this;
$storedCard->card = $card;
$storedCard->save();
$profiles = $transaction->member->cm_profiles;
$data['customer'] = $profiles[ $this->id ];
$data['card'] = $storedCard->data;
@@ -204,6 +239,15 @@ class _Stripe extends \IPS\nexus\Gateway
/* Authorize */
$response = $this->api( 'charges', $data );
$transaction->gw_id = $response['id'];
$extra = $transaction->extra;
$extra['stripe'] = array(
'risk_level' => $response['outcome']['risk_level'],
'card' => $response['source']['object'] == 'card' ? array(
'type' => $response['source']['type'],
'last4' => $response['source']['last4'],
) : NULL,
);
$transaction->extra = $extra;
/* Return */
return \IPS\DateTime::ts( $response['created'] )->add( new \DateInterval( 'P7D' ) );
@@ -256,6 +300,21 @@ class _Stripe extends \IPS\nexus\Gateway
$this->api( "charges/{$transaction->gw_id}/refund", $data );
}
/**
* Extra data to show on the ACP transaction page
*
* @param \IPS\nexus\Transaction $transaction Transaction
* @return string
*/
public function extraData( \IPS\nexus\Transaction $transaction )
{
if ( isset( $transaction->extra['stripe'] ) )
{
return \IPS\Theme::i()->getTemplate( 'transactions', 'nexus', 'admin' )->stripeData( $transaction->extra['stripe'] );
}
return NULL;
}
/* !ACP Configuration */
/**