Collections functions
General functions
Render functions
Theme permission functions
User functions
Resource functions

payment_set_complete()

Description

Update ecommerce user's basket to indicate it has been purchased after PayPal callback (invoice users will pactually ay later with manual invoicing)

Parameters

ColumnTypeDefaultDescription
$collection int
$emailconfirmation string - LEGACY MUNUSED

Return

boolean

Location

include/resource_functions.php lines 8111 to 8178

Definition

 
function payment_set_complete($collection)
    {
    global 
$applicationname,$baseurl,$userref,$username,$admin_resource_access_notifications,$userfullname,$lang,$currency_symbol;
    
// Mark items in the collection as paid so they can be downloaded.
    
ps_query("UPDATE collection_resource SET purchase_complete=1 WHERE collection=?",["i",$collection]);

    
// For each resource, add an entry to the log to show it has been purchased.
    
$resources=ps_query("SELECT * FROM collection_resource WHERE collection=?",array("i",$collection));

    
// Construct summary, separating lang entries from fixed text
    
$summaryparts = [];
    
$summaryparts[] = "<style>.InfoTable td {padding:5px;}</style><table border=\"1\" class=\"InfoTable\"><tr><td><strong>";
    
$summaryparts[] = "lang_property-reference";
    
$summaryparts[] = "</strong></td><td><strong>";
    
$summaryparts[] = "lang_size";
    
$summaryparts[] = "</strong></td><td><strong>";
    
$summaryparts[] = "lang_price";
    
$summaryparts[] = "</strong></td></tr>";

    foreach (
$resources as $resource)
        {
        
$purchasesize=$resource["purchase_size"];
        if (
$purchasesize=="")
            {
            
$purchasesize=$lang["original"];
            }
        
resource_log($resource["resource"],LOG_CODE_PAID,0,"","","",0,$resource["purchase_size"],$resource["purchase_price"]);

        
$summaryparts[] = "<tr><td>" $resource["resource"] . "</td><td>";
        
$summaryparts[] = ($purchasesize=="" "lang_original" $purchasesize);
        
$summaryparts[] = "</td><td>" $currency_symbol $resource["purchase_price"] . "</td></tr>";
        }
    
$summaryparts[] = "</table>";

    
// Construct message components
    
$notify_users=get_notification_users("RESOURCE_ACCESS");
    
$notifymessage = new ResourceSpaceUserNotification();
    
$notifymessage->set_text("lang_purchase_complete_email_admin_body");
    
$notifymessage->append_text("<br/><br/>");
    
$notifymessage->append_text("lang_username");
    
$notifymessage->append_text(": " $username " (" $userfullname ")<br/><br/>");
    foreach(
$summaryparts as $summarypart)
        {
        
$notifymessage->append_text($summarypart);
        }
    
$notifymessage->user_preference = ["user_pref_resource_access_notifications"=>["requiredvalue"=>true,"default"=>$admin_resource_access_notifications]];
    
$notifymessage->set_subject("lang_purchase_complete_email_admin");
    
$notifymessage->url $baseurl "/?c=" $collection;
    
send_user_notification($notify_users,$notifymessage);

    
// Send email to user (not a notification as may need to be kept for reference)
    
$userconfirmmessage = new ResourceSpaceUserNotification();
    
$userconfirmmessage->set_text("lang_purchase_complete_email_user_body");
    
$userconfirmmessage->append_text("<br/><br/>");
    foreach(
$summaryparts as $summarypart)
        {
        
$userconfirmmessage->append_text($summarypart);
        }
    
$userconfirmmessage->set_subject("lang_purchase_complete_email_user");
    
$userconfirmmessage->url $baseurl "/?c=" $collection;

    
send_user_notification([$userref],$userconfirmmessage,true);

    
// Rename so that can be viewed on my purchases page
    
ps_query("UPDATE collection SET name = ? WHERE ref = ?",["s",date("Y-m-d H:i"),"i",$collection]);

    return 
true;
    }

This article was last updated 29th November 2023 07:35 Europe/London time based on the source file dated 21st November 2023 09:30 Europe/London time.