Thread: [INC] PayPal
View Single Post
Author Message
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-21-2013 , 22:18   [INC] PayPal
Reply With Quote #1

PayPal
Enables transactions through MOTD.

I am not responsible for errors or failed transactions!
Use this at your own risk.


Credits:
xPaw for SourceQuery.
bboygrun for the tutorial on how to use SourceQuery.
Exolent[jNr] for the stock str_explode() that I stole from his String Stocks library.

Requirements:
* A PayPal account that has the following enabled under "Website Payment Preferences":
- Auto Return.
- Payment Data Transfer.
- An Identity Token, found on the same page after PDT is enabled.

* SourceQuery.
- Place the files from SourceQuery in a folder named "SourceQuery".
- Place that folder in the same folder as the PHP file.

* HTTP2 v2.21(or higher) for payment verification.

* A webserver to host the PayPal.php.

How it works:
As promised, I will explain.

You start a session using PayPal_Start().
This will format the PayPal link and open a MOTD that will redirect the user to the PayPal link.

When the user completes the payment he/she will be redirected to the PayPal.php that you host and specified earlier.
The .php utilizes SourceQuery to execute a command on your server, passing the Transaction ID to the server.

The server receives the command and verify the payment using HTTP2.
HTTP2 will pass the Transaction ID and the Identity Token as POST variables directly to a PayPal verification link. This prevents tampering.
This will result in a text-based page that gives specifics about the payment and if it was successful.
HTTP2 will download that like any file and then the PayPal.inc will parse the information calling the PayPal_Complete() forward on success.

If a user leaves the server before the process is completed the SteamID will be saved in a que file, so when the person reconnects PayPal_Complete() will be called.

Once a transaction is verified it will blacklist that Transaction ID in a file so people won't be able to receive whatever "benefits" by refreshing the page over and over.

If the transaction fails or gets aborted nothing will be called.

Functions:
Code:
/* To customize your PayPal session further, a full list of GET variables can be found here: <a href="https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/#id08A6HI0709B" target="_blank" rel="nofollow noopener">https://developer.paypal.com/webapps...#id08A6HI0709B</a> */ #define TRANSACTION_FILENAME "PayPalTransactions.dat" #define QUE_FILENAME "PayPalQue.dat" /* PayPal_setAccount(const Account[]) * Defines your PayPal Account to receive the payment. */ stock PayPal_setAccount(const Account[]) /* PayPal_setIdentityToken(const IDToken[]) * * Defines PayPal Identity Token which is used to verify the payment. * * More information can be found here: * <a href="https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/paymentdatatransfer/" target="_blank" rel="nofollow noopener">https://developer.paypal.com/webapps...tdatatransfer/</a> */ stock PayPal_setIdentityToken(const IDToken[]) /* PayPal_setReturnURL(const ReturnURL[]) * * Defines the URL to PayPal.php. * * (Optional. If not set the default in PayPal account will be used.) */ stock PayPal_setReturnURL(const ReturnURL[]) /* PayPal_setCurrency(const Currency[]) * * 3-digit currency code. * * (Optional. If not set USD will be assumed.) * * A list of valid currencies can be found here: * <a href="https://developer.paypal.com/webapps/developer/docs/classic/api/currency_codes/" target="_blank" rel="nofollow noopener">https://developer.paypal.com/webapps...urrency_codes/</a> */ stock PayPal_setCurrency(const Currency[]) /* PayPal_setLogo(const Logo[]) * * Link to a logo image to display at top-left corner instead of your account name. * Max: 150x50px according to PayPal, does however fit larger images without problems. * In the example picture the 350x100 is cut off at the bottom. * * (Optional.) */ stock PayPal_setLogo(const Logo[]) /* PayPal_setHTMLBody(const HTMLBody[]) * * What to display in the _PayPal_MOTD while loading the PayPal website. * More or less just to clear the server _PayPal_MOTD. * * (Optional. If not set a general "Loading..." will be used.) */ stock PayPal_setHTMLBody(const HTMLBody[]) /* PayPal_Start(id, const ItemName[], const ItemNumber[], Float:Amount = 0.0) * * Formats and displays a MOTD with PayPal. * * id is the person to show the MOTD to. * * ItemName[] and ItemNumber[] could be used however you want. Both are visible on payment screen. * I suggest using ItemName as an actual name to display to the person paying. For example "1 month of VIP". * ItemNumber should be used like any article number. This way you'll be able to keep track which payment has reached the forward. * * Amount is of course the amount of money in previously selected currency that you want to charge. * If left at 0, the user can input any number him-/herself. It will also open the "donation" design instead of the "pay" design. */ stock bool:PayPal_Start(id, const ItemName[], const ItemNumber[], Float:Amount = 0.0) /* PayPal_Complete(id, ItemName[], ItemNumber[], Float:Amount, Currency[]) * * This forward will be called when the payment is done and verified. * Keep in mind that floats in PAWN are not 100% accurate. So compare the Amount with a margin of error. */ forward PayPal_Complete(id, ItemName[], ItemNumber[], Float:Amount, Currency[]);

Examples:
Code:
#include <amxmodx> #include <PayPal> public plugin_init() {     register_plugin("PayPalExample", "1.0", "[ --{-@ ]");         PayPal_setAccount("MyPayPalAccount");     PayPal_setIdentityToken("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");     PayPal_setReturnURL("http://mywebsite/PayPal.php");     PayPal_setCurrency("SEK");     PayPal_setLogo("http://mywebsite/mybanner.png");     PayPal_setHTMLBody("<font color=red>Where are we going?</font>");         register_clcmd("test", "testcmd"); } public testcmd(id)     PayPal_Start(id, "This is ItemName", "This is ItemNumber", 15.0); public PayPal_Complete(id, ItemName[], ItemNumber[], Float:Amount, Currency[]) {     new name[32];     get_user_name(id, name, charsmax(name));     server_print("%s completed payment for ^"%s^"(%s), with %.2f %s.", name, ItemName, ItemNumber, Amount, Currency); }

Code:
Inc logging:
L 09/24/2013 - 01:31:54: [test1.amxx] [PayPal] Black Rose(STEAM_0:1:*snip*) completed payment for "This is ItemName"(This is ItemNumber), with 15.00 SEK. (*snip*)
Example Plugin:
Black Rose completed payment for "This is ItemName"(This is ItemNumber), with 15.00 SEK.
Payment design (Predetermined amount):


Donation design (Amount = 0.0):


Additional notes:
As always, you're not forced to use this as an include. You can use this in any way you want to.
You can, if you want, copy the whole thing into your .sma without even crediting me. My goal is not credit, It's to help.

I'm always open to suggestions, feedback and criticism. I aim to add as much support as possible. Please share your thoughts.
Attached Files
File Type: inc PayPal.inc (13.7 KB, 641 views)
File Type: txt PayPal.php.txt (1.0 KB, 529 views)
__________________

Last edited by Black Rose; 01-22-2021 at 20:56.
Black Rose is offline