Giter Club home page Giter Club logo

coinpayments's Introduction

CoinPayments

A PHP implementation of CoinPayments Payment Gateway wrapped up into a simple to use class.

Introduction

This is a one file class with simplicity at its core. I wanted to create a simple to use IPN that works with both paypal and bitcoin, because they are the most requested payment systems. Before you continue reading this, you should head over to https://www.coinpayments.net/merchant-tools-ipn#setup and make sure your account is ready to use with thew IPN. You do not need to setup a IPN url on coinpayments, you can do it in the code.

How to Use

This class is very simple to use, you need to simply include the coinPayments.class.php file and initialize it.

require 'src/MineSQL/CoinPayments.php';

$cp = new \MineSQL\CoinPayments();

$cp->setMerchantId('your_merchant_id_on_coinpayments');
$cp->setSecretKey('your_secret_key_you_defined_in_account_settings_on_coinpayments');

Now the coinpayments class is ready to do one of two things, either create a payment or recieve a callback notification.

Creating A New Payment

there are many optional settings that you should probably set as well: https://www.coinpayments.net/merchant-tools-buttons

...

// You are required to set the currency, amount and item name for coinpayments. cmd, reset, and merchant are automatically created within the class


// REQUIRED
$CP->setFormElement('currency', 'USD');
$CP->setFormElement('amountf', 12.50);
$CP->setFormElement('item_name', 'Test Item');
//OPTIONAL
$CP->setFormElement('custom', 'customValue235');
$CP->setFormElement('ipn_url', 'http://minesql.me/ipn/cp');

// After you have finished configuring all your form elements, 
//you can call the CoinPayments::createForm method to invoke 
// the creation of a usable html form.
echo $CP->createForm();

Next, You need to know how to complete the callback (or IPN).

// we pass the $_POST and $_SERVER variables to alleviate any actual dependencies in the class when testing/troubleshooting.
// in the future, methods will be used within CoinPayments:: to grab the $_POST and $_SERVER variables in order to maintain easy of use
// as well as sound pattern design
try {
if($CP->listen($_POST, $_SERVER)) 
{
	// The payment is successful and passed all security measures
	// you can call the DB here if you want
	
} 
else 
{
	// the payment is pending. an exception is thrown for all other payment errors.
}
}
catch(Exception $e) 
{
	// catch the exception and decided what to do with it. (most likely log it)
}

In order for the payment to actually validate in the class, the request has to be verified through either HMAC or httpauth. Both work seemlessly in the application and is totally plug and play, the source does not need to be modified. The method of verification can be changed in the CoinPayments merchant settings panel.

Error Catcher

This application has an error catching mechanism so you can easily differentiate errors.

Any errors will invoke a new Exception to be called. I am still working on this feature to have named Exceptions for better usability, but for now they simply give detail error messages.

Misc.

For now the button is not easy to modify, but it does have a class name 'coinpayments' so you can add whichever styles you want to it through this class. In the future I might make the button styling more dynamic.

Closing

I love help, if you think you can make this class better make a pull request! :)

coinpayments's People

Contributors

minesql avatar owenvoke avatar taylorchristie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

coinpayments's Issues

Testing

testing needs to be done for the class to ensure it works.

Call Back

Hi,

i have an issue with call back url. can you provide an example with mysql

IPN / Callback issue

When I have paid the amount in BTC it said PAID but it won't redirect or anything back to my website. It just gets stuck. I set my IPN_URL to the callback script on my server.

Am I being stupid? What am I doing wrong?

payment status on my site

I want payment status(success or pending) and transaction id on my site. I am transferring amount through this IPN code but I am not understood how to get transaction id and payment status update on my site.
Please help me.

Code Commenting

all methods and properties need to be properly commented, and higher complexity logic needs to be commented on as well.

What i do to get call back

PHP Catchable fatal error: Argument 1 passed to MineSQL\CoinPayments::callbackError() must be an instance of MineSQL\int, integer given, called in
/src/MineSQL/CoinPayments.php on line 76 and defined in
src/MineSQL/CoinPayments.php on line 144

Passing "Custom" to my IPN but its not being set?

I am passing custom (the passthru variable) to the IPN but I cannot call it in your callback.php file.

For example:
$CP->setFormElement('custom', 'Example1'); - In creating transaction.

Attempting to call it: $_POST['custom'] = However, it returns nothing.

One last thing, is there a better way to test this rather than my consistently creating a transaction and in my callback file inserting it into a database.

Nevertheless, any ideas on why I cannot call the custom variable?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.