Version 4.7.23
This commit is contained in:
1 parent
7124a02564
commit
25ddeb65d6
1791 files changed
+76990
-44452
No files matched your search
@@ -54,26 +54,48 @@ try
|
||||
/* Subscription */
|
||||
if ( isset( \IPS\Request::i()->subscription ) )
|
||||
{
|
||||
/* Sometimes PayPal doesn't include the subscription ID, so let's check if we have it in the transaction */
|
||||
$subscriptionId = \IPS\Request::i()->subscription_id ?? $transaction->gw_id;
|
||||
|
||||
/* If we have no subscription ID, but the transaction is already linked to a Billing agreement, use that */
|
||||
if( empty( \IPS\Request::i()->subscription_id ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$billingAgreement = \IPS\nexus\Gateway\PayPal\BillingAgreement::load( \IPS\Db::i()->select( 't_billing_agreement', 'nexus_transactions', [ 't_id=?', $transaction->id ], flags: \IPS\Db::SELECT_FROM_WRITE_SERVER )->first() );
|
||||
}
|
||||
catch( \OutOfRangeException | \UnderflowException )
|
||||
{
|
||||
/* Log it, along with the whole request, so that we can try to see what's happening */
|
||||
\IPS\Log::log( "Missing subscription_id " . print_r( \IPS\Request::i(), true ), 'paypal' );
|
||||
throw new Exception( \IPS\Member::loggedIn()->language()->get( 'billing_agreement_start_error' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Get details */
|
||||
$response = $transaction->method->api( "billing/subscriptions/" . \IPS\Request::i()->subscription_id, NULL, 'get' );
|
||||
|
||||
/* Create Billing Agreement */
|
||||
try
|
||||
if( !isset( $billingAgreement ) )
|
||||
{
|
||||
$billingAgreement = \IPS\nexus\Gateway\PayPal\BillingAgreement::constructFromData( \IPS\Db::i()->select( '*', 'nexus_billing_agreements', array( 'ba_gw_id=? AND ba_method=?', $response['id'], $transaction->method->id ) )->first() );
|
||||
$response = $transaction->method->api( "billing/subscriptions/" . $subscriptionId, NULL, 'get' );
|
||||
|
||||
/* Create Billing Agreement */
|
||||
try
|
||||
{
|
||||
/* @note SELECT_FROM_WRITE_SERVER transaction race condition */
|
||||
$billingAgreement = \IPS\nexus\Gateway\PayPal\BillingAgreement::constructFromData( \IPS\Db::i()->select( '*', 'nexus_billing_agreements', array( 'ba_gw_id=? AND ba_method=?', $response['id'], $transaction->method->id ), flags: \IPS\Db::SELECT_FROM_WRITE_SERVER )->first() );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
$billingAgreement = new \IPS\nexus\Gateway\PayPal\BillingAgreement;
|
||||
$billingAgreement->gw_id = $response['id'];
|
||||
$billingAgreement->method = $transaction->method;
|
||||
$billingAgreement->member = $transaction->member;
|
||||
$billingAgreement->started = \IPS\DateTime::create();
|
||||
$billingAgreement->next_cycle = ( new \IPS\DateTime( $response['billing_info']['next_billing_time'] ) );
|
||||
$billingAgreement->save();
|
||||
}
|
||||
$transaction->billing_agreement = $billingAgreement;
|
||||
$transaction->save();
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
$billingAgreement = new \IPS\nexus\Gateway\PayPal\BillingAgreement;
|
||||
$billingAgreement->gw_id = $response['id'];
|
||||
$billingAgreement->method = $transaction->method;
|
||||
$billingAgreement->member = $transaction->member;
|
||||
$billingAgreement->started = \IPS\DateTime::create();
|
||||
$billingAgreement->next_cycle = ( new \IPS\DateTime( $response['billing_info']['next_billing_time'] ) );
|
||||
$billingAgreement->save();
|
||||
}
|
||||
$transaction->billing_agreement = $billingAgreement;
|
||||
$transaction->save();
|
||||
|
||||
/* Check Fraud */
|
||||
$fraudResult = $fraudCheck( $transaction, FALSE );
|
||||
|
||||
Reference in new issue
Block a user