How to check wallet for balance? - php

I am having trouble because I have a website in PHP and I am using a library to communicate with my bitcoin server node over the RPC.
Everything is good and bitcoin can communicate with the website. I am generating new wallet using the command
getnewaddress "label"
The bitcoin then returns the new bitcoin address with label what I sent over the RPC and that works really good and very well. The thing is that I must check that wallet next 15 minutes and after 15 minutes if user submit the form with button "paid" I must once again check for balance of the wallet, if the wallet has the right balance server will send him the product over email.
In the past I know we could use watch wallet but as that has been deleted from the RPC I am having trouble with checking that wallet, also what would be the best approach of the checking something with PHP in x time?

I would suggest you regularly run bitcoin RCP command listsinceblock. Keep track of the last block you checked in a database or cache, and run this command in your preferred interval (example: 15 minutes). This will return all new transactions since the last time you ran the command.
If there are transactions, the destination wallet address will be included in the commands response.
Wiki explains the command pretty well:
listsinceblock [blockhash] [target-confirmations]
Get all transactions in blocks since block [blockhash], or all transactions if omitted. [target-confirmations] intentionally does not affect the list of returned transactions, but only affects the returned "lastblock" value.
Source

Related

Google Wallet/PHP: Handling Postbacks with uncertain charge result

In PHP, when handling the postback from Google Wallet confirming a purchase, it's possible that the server will not reply within the ten second time limit--this is sometimes completely undetectable serverside.
What should I do to prevent this? Is there a way to confirm the purchase was successful?
Google Wallet for Digital Goods will fail for both you (merchant) and the user/buyer if you don't respond to the postback as required.
Important: If you specify a postback URL, your server must respond promptly and correctly to the HTTP POST messages that Google sends for each transaction. Otherwise, the transaction will be canceled.
REF: https://developers.google.com/commerce/wallet/digital/docs/postback
If you're saying your system may think the trnx is "good" and it just took time to respond (at which point Google already canceled) - there is a "verification step" that occurs on successful transactions - success handler. You can use that to "confirm" the order on your end. So if Google canceled the transaction, your system will not get this final (re)confirmation (because your success handler will not be called).
I guess you could also use the failure handler for this, though it won't have an "orderId"
Hth...
As a side note on the comments, Google Checkout was also renamed Wallet at some point. If memory serves, it was really more for buyers than for merchants...so yes, do check on what API you are referring to.
This answer is specific to Wallet For Digital Goods (it is completely separate from Google Checkout/Wallet, which also included some support for digital purchases).
See this link announcement

Run php script in background on nginx

I'm trying to develop a payment module for one shop cms.
Payment is based on acquiring in a Bank.
So firstly for each order creates (with curl) a "ticket" on bank side. Ater that client is forwarded on payment page on bank server with its ticket id. If customer pays and push button "go back to store" everything is fine.
But if customer pays and don't push this button i need to check the result (if he paid or not). It is also made by curl. I'm requesting info by ticket id and receive an array with parameters i need among them is result code i need to check.
So i need to check it automatically (for ex. 1 time each 5 mins during an hour).
Cron can't help me coz it is all dynamically processes.
I created a function that returns me the result. But how can i start it in background with any interval?
Using cron. PHP does not offer anything like scheduler because it is out of scope of the language. You may use DB to store some of parameters needed to the whole process.
I'll extend a little bit WebnetMobile answer on using cron for what you want.
Likely you have a table in your DB where you store are tickets you get from Bank and whenever they suceed or did not suceed as well the date the ticket was created.
Then, if what you want is to check every five minutes from bank ticket creation date whetever it suceed or not if unknown, you should run a cron each minute that will do the following:
Check if there are bank tickets without defined state (Suceed or Failed).
Check if time created (without seconds) minus current time (without seconds) MOD 5 == 0.
If true, means another 5 minutes period have passed from that ticket creation and should be checked, Else do nothing.
I think this will do what you want

How to retrive email reciept generated by authorize.net

I have a maintenance project which uses Authorize.Net for payment. Currently, the system provides an email receipt provided by the gateway. Is there any way to grab the receipt and display on the thank you page as a printable receipt ?
Help would be appreciated.
Not realistically. It's hard to say exactly how you would do this since which API you are using will affect your programming, but technically you can pipe the copy of the receipt sent to you into a PHP program which would then place it into a database or flat file. Meanwhile you can have your PHP script waiting for the file or database record to exist and, when it does, output it to the screen.
This would be a bad plan for several reasons:
If the email never arrives your user could be left waiting for a receipt that never comes. That could result in unhappy users and potentially chargebacks.
Even if this works it will be slow which will also result in lower customer satisfaction.
This is a hack.
There are much better ways to provide a printable receipt to your users. If you're using the AIM, ARB, or CIM APIs you have instant access to the response from Authorize.Net. You can easily generate your own printable receipt for them with this information. If you're using SIM you can use relay response to get the transaction information from Authorize.Net to accomplish the same thing.
These are better solutions because:
They're fast. You will get a response from Authorize.Net within seconds and can print out the information in less then a second.
You have total control of the receipts content and appearance.
It's reliable. You can count on getting a fast response every time.
If working with APIs seems daunting to you, you may find using their Silent Post feature appealing. It's just like Paypal's IPN where after a transaction is processed, regardless of which API you use, all of the transaction information is sent to a PHP script you specify. It is POSTed just like a form submission so it's easy to work with. You can then email your users a receipt with that information.
Disclaimer: I wrote the Sitepoint chargeback article and the Silent Post article

How to create a "pending" order in authorize.net?

I'm a web developer looking to move a lot of clients to use authorize.net for their CC processing. I have used authorize.net once in PHP doing SIM integration for a simple site.
Now the problem is, some of our clients have established processes that takes the CC info from our site, and it goes through a fulfillment process outside the control of our site. In at least one case, the client uses the CC info to bill for shipping after it's packaged, long after it leaves our website, because of international rates.
The main reason of using authorize.net is security. We want to be PCI compliant so the idea is that the CC never even goes through our web server. It is entered on authorize.net and never leaves there. So I need to figure out the API to conduct this process.
So my question is, without ever handling the CC info, how do I create a "pending" transaction that takes the user's cc info at one point, and then has the cost updated at another point? I am picturing I will have to tell the client to log back into our site (or authorize.net) to update the cost of the order.
All I have found is this FAQ, my question is the same as the top, but it isn't clear if I have to keep the CC info to do this process, which I simply cannot do.
http://www.inventiveweb.com/RoboCharge/faq.htm
Can it be done?
OK they have great support at authorize.net and an excellent knowledge base. I bet their support guys just paste out of the database.
As outlined in the link above, if you know the high-end of the costs, you can pad, and do an AUTH_ONLY followed by a PRIOR_AUTH_CAPTURE.
As of now there is no API for this, but you can log into your authorize.net account and perform a re-bill. Transactions are stored for up to 90 days, so you can then issue a new transaction with a re-bill and you don't need the CC info.
The downside? A re-bill only works on a successfully settled transaction, and that takes 1-3 days.

Integrating Fedex into your web application

I realize they have an API but some of
the questions I have wouldn't be
answered by it, and it would be great
to receive feedback from others who
have integrated it before.
I basically am working with a web site where visitors may choose to sell a used item to the site owner.
If the user decides to sell, he can enter in the specifications of the item and be given a quote. Then he'll proceed to enter in his address, which I assume I'll have to verify using the Fedex API before or during the part where it creates a shipping label.
So assuming the address is verified, it looks like the script in the API I have to interact with is /Ship/Ground/Domestic/ShipGroundDomestic.php5 ( since we will not integrate any other type of shipment type yet ).
Is this is the script that actually creates the shipment and charges the account setup, assuming all goes well it returns a xml response with the status?
Since it's SOAP based - I realize there are options for a pdf and png shipping label type, it looks like it generates the label but where is it actually stored, is it just temporary?
In the script it specifies options for a API Key, password, account #, and Meter # - so I would have to actually know the site owners credentials, since it charges for creating shipments/labels I can't use a normal account that doesn't have a CC setup, can I?
I can't actually test anything without contacting them and telling them to make my account go into test mode? Or is there an extra parameter for test mode?
I should store all shipments in a local database to pull them up, right? Or should I solely rely on Fedex for storing all the information? If I use a local database I can map shipments to users and use a Fedex provided script to look up the delivery status so I would think I have to do that.
If I were to have a feature that automatically emailed customers with status updates of a delivery, I would have to use some type of cron job to look and see if there were any updates made, I can't do this any other way?
If you are using the the Fedex Web Services API you get a test key by going to https://www.fedex.com/wpor/wpor/editConsult.do
(You may need to be already signed in).
The label it generates it just dumps into the current directory. That is obviously not acceptable for production code, since it does not even generate a unique file name, but the php file is example code. Modify the code they give to do whatever you want with the returned label.
You would want a local database.
Why would you want to send users updates? Is there any reason they cannot just use the tracking number and look it up themselves? I mean it would be possible to call the tracking API periodically and generate emails, but do users really want these emails?

Categories