How to set up the Shop inside of IPB forums with donation claim
Solak 718 Releases
As I promised to a few people, once I got this working and finished, I would release it for others to use. This includes setting up the shop inside of the forums to correctly purchase and claim inside of your server.
*The claim script was built in a 718+ server, so you may have to change it a bit*
Step 1 : Setting up Payment Options
Go to your control panel, under
Commerce, Go to
Payments -
Settings.
Go to the second tab
Payment Methods and hit
Create New button.
In this example, we will set up
PayPal.
Click on
PayPal option and click
Save.
On the next page, name it
PayPal, check the
Disabled: Do not use Subscriptions option, and next you need a
Client ID and
Secret ID. This uses
REST API for passing information to and from payment gateways.
Click on the blue text under the Client Id box
create an application on PayPal's developer site. Create a developer account if you havent so already.
Create a REST API Application, name it, select
Merchant – Accept payments as a merchant (seller) option, and use your live account.
After creating these, you will receive a
Client ID and click reveal to get your
Secret ID. Place those back in the store setting page, and click
Save.
Payment Method Set Up Done
Create The Store and Products
Go into
Products, under
Store in the
Commerce sidebar.
Create a new group, this will be your categories.
After creating a group, create an item for purchase. by pressing the + button under the group,
Add Product To This Group
Create your product, adding images, name, description, price, stock, etc to the store.
IMPORTANT
Under the option on first page is
Custom Fields. Create a custom field, by clicking
custom field settings below the bar.
Create a new custom field, lets say
In-Game Name.
Go back to finishing the product and make sure you add your new custom field to
ALL PRODUCTS you are selling now and in the future.
Creting products done.
IMPORTANT!!
Go into your database where your forums is, go into the table "nexus_purchases" and create a column "ps_claimed" as INT and set it to default 0.
Store Claim Script
Here is the store claim script you can use, that includes pulling in the name, checking price on invoice to prevent nulls or errors. Again this is built on 718+ so might have to change it, but make sure your RESULTSET query is not messed with.
Code:
package quantum.site;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.rs.game.player.Player;
/**
* @author Quantum
* This is for Store Claiming
* new Thread(new StoreClaim(player)).start();
*/
public class StoreClaim implements Runnable {
public static final String HOST = ""; // website ip address
public static final String USER = "";
public static final String PASS = "";
public static final String DATABASE = "";
private Player player;
private Connection conn;
private Statement stmt;
String name_claim;
public StoreClaim(Player player) {
this.player = player;
}
public void run() {
try {
if (!connect(HOST, DATABASE, USER, PASS)) {
return;
}
String name = player.getDisplayName().replace("_", " ");
ResultSet connect = executeQuery("SELECT * FROM nexus_purchases WHERE JSON_VALUE(ps_custom_fields, '$.1') = '"+name+"' AND ps_claimed = 0 AND ps_cancelled = 0");//Dont touch
while (connect.next()) {
int packageID = connect.getInt("ps_item_id");
player.sm("You have a purchase ready to be claimed!");
switch(packageID) {
/**
* Add your packages claiming here (go by ps_item_id)
*/
case 1:
break;
}
connect.updateInt("ps_claimed", 1);
connect.updateRow();
}
destroy();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
*
* @Param host the host ip address or url
* @Param database the name of the database
* @Param user the user attached to the database
* @Param pass the users password
* @Return true if connected
*/
public boolean connect(String host, String database, String user, String pass) {
try {
this.conn = DriverManager.getConnection("jdbc:mysql://"+host+":3306/"+database, user, pass);
return true;
} catch (SQLException e) {
System.out.println("Failing connecting to database!");
return false;
}
}
/**
* Disconnects from the MySQL server and destroy the connection
* and statement instances
*/
public void destroy() {
try {
conn.close();
conn = null;
if (stmt != null) {
stmt.close();
stmt = null;
}
} catch(Exception e) {
e.printStackTrace();
}
}
/**
* Executes an update query on the database
* @Param query
* @see {@link Statement#executeUpdate}
*/
public int executeUpdate(String query) {
try {
this.stmt = this.conn.createStatement(1005, 1008);
int results = stmt.executeUpdate(query);
return results;
} catch (SQLException ex) {
ex.printStackTrace();
}
return -1;
}
/**
* Executres a query on the database
* @Param query
* @see {@link Statement#executeQuery(String)}
* @Return the results, never null
*/
public ResultSet executeQuery(String query) {
try {
this.stmt = this.conn.createStatement(1005, 1008);
ResultSet results = stmt.executeQuery(query);
return results;
} catch (SQLException ex) {
ex.printStackTrace();
}
return null;
}
}
Hope you all enjoy!