Mark Posted May 13, 2010 Posted May 13, 2010 One of the first things I wanted to talk about with IP.Nexus is how easy it is for third-party developers to integrate with IP.Nexus. You could for example, have an area of your application that you only want available to users who pay a fee. IP.Nexus makes this possible. There is a special class in IP.Nexus called commerceApi that allows you to generate an invoice, and check if an item has been purchased. In addition, you can make use of special extension files to automatically run when an item from your application is purchased, expires or is renewed - and your items can appear in the Admin CP "Generate Invoice" page. For example, we have written integration for IP.Nexus with IP.Downloads using this functionality, which we will demonstrate in a future blog entry. For developers, to generate an invoice, you simply call the commerceApi::generateInvoice() method. This is the code we use within the donation module of IP.Nexus: try { $title = "Donation: {$goal['d_name']}"; $invoiceID = commerceApi::generateInvoice( $title, $this->memberData['member_id'], array( array( 'act' => 'charge', 'app' => 'commerce', 'type' => 'donation', 'cost' => $amount, 'itemName' => $title, 'itemID' => $goal['d_id'] ) ) ); } catch( Exception $e ) { $this->registry->output->showError( "An error occurred while trying to generate your invoice. Please try again or contact an administrator. ({$e->getMessage()})", 12345 ); } $this->registry->getClass('output')->silentRedirect( $this->settings['base_url'] . 'app=commerce&module=payments&section=pay&id=' . $invoiceID ); As you can see, the code passes some information about the item(s) being purchased. At this point, commerceApi generates an invoice, and then the user is sent to the payment screen. Once payment has been processed, the user will be sent right back to the file. Using this functionality you can:Specify a base cost for your itemSpecify renewal termsProvide a URL to the item which will be linked to on the invoice screenSpecify a member who should get commission for the purchase and how much commission to give them (for example, if the item was added by another member)Specify a URL to return the user to once payment has been received Later in your code, to check if a user has purchased an item (for example, when they try to access a restricted area) you just call commerceApi::itemIsPurchased() to check if they have paid for the item. if ( commerceApi::itemIsPurchased( $this->memberData['member_id'], 'myapp', 'item_type', $data['id'] ) != 'ACTIVE' ) { // Item not purchased... } commerceApi::itemIsPurchased() will return a value indicating whether the item was purchased, and if the renewals are active. As you can see, the API is very simple to use and means mod authors do not have to worry about implementing payment systems in their own applications. We're really excited to see how mod authors will use this functionality and as always, if you have any questions, please post them in our feedback forum. Our next blog entry will demonstrate how we used this functionality to implement paid files within IP.Downloads. View full blog entry
Recommended Posts