I'm currently building a site that will offer services that customers can pay for in Dogecoin. I am using DogeAPI and these example checkout scripts to try and build my checkout pages.
The problem is I can't get the address ($new_address) to echo to the page. When I run the script all that shows up is "Please pay 1000 DOGE to to receive your item. It may take up to 10 minutes to confirm your payment." When I log into my dashboard on DogeAPI, it doesn't show that any addresses were created.
I have a feeling that I need some sort of code that will wait until file_get_ contents() is finished and then start the JSON decoding. My code is below.
NOTE: I do have the API key in my code, I just obviously removed it before posting the code here.
//set to your API_KEY
$api_key = 'MY API HERE';
//set this to your users id
//must be alphanumeric only
$user_id = 'test123';
//set this to the amount the item costs
$amount_doge = '1000';
//send a request to the API to make a new payment address
//put info about the request in
$response = file_get_contents("https://www.dogeapi.com/wow/?api_key=$api_key&a=get_new_address&address_label=$user_id");
if($response !== 'Bad Query' && $response !== '') {
$new_address = json_decode($response);
//insert the new pending payment
mysql_query("INSERT INTO `api_payments`
(`payment_label`,`payment_address`,`paid`,`amount`)
VALUES ('$user_id', '$new_address', '0', '$amount_doge')");
//give them the address or echo a widget here
//for this example we will just echo an address
echo "Please pay $amount_doge DOGE to $response to receive your item. It may take up to 10 minutes to confirm your payment.";
} else {
echo 'There was a problem processing your order.';
}
Related
I deal with a payment gateway provider and I have been facing a problem for days and I cannot solve it, the problem is simply that the customer pays after completing the order, arriving to the payment page (online banking) and the user may close the page of the bank after completing the payment process and do not click on the return button to the merchant page Here comes the job of the return url ( Enable Instant Payment Notification (IPN)) that the provider asked me to set up and I did, but the link sometimes works and often it does not work, when I asked the provider they said the error is:
kindly be informed that we received message status ::35 - SSL Connect Error in most of the transaction.
In this case, please assist to have a check at your end for the mentioned error and client URL (cURL).
I don't know where to go to check the curl as you see in my code there is no curl!! and Im using forge laravel so I'm not able to check the server log and even in laravel logs I can't see the error mentioned by provider
here my post url
public function getStatus()
{
$vkey = config('services.payment.secret');// secret key
$tranID = $_POST['tranID'];
$orderid = $_POST['orderid'];
$status = $_POST['status'];
$domain = $_POST['domain'];
$amount = $_POST['amount'];
$currency = $_POST['currency'];
$appcode = $_POST['appcode'];
$paydate = $_POST['paydate'];
$skey = $_POST['skey'];
$key0 = md5( $tranID.$orderid.$status.$domain.$amount.$currency );
$key1 = md5( $paydate.$domain.$key0.$appcode.$vkey );
if( $skey != $key1 ) $status= -1; // Invalid transaction
if ( $status == "00" ) {
SavingPaymentAction::SendEmailAfterCharge($orderid);
}
else {
SavingPaymentAction::SendErrorEmail($orderid);
}
}
I used php-telegram-bot/core to create a shopping bot in telegram.
What I want to do is when a User make an order, bot send a notification that a new Order is come to admin of Channel.
Suppose admin channel username is like #admin_username and stored in a global variable(means that may be change in a period of time). for that I wrote this :
static public function showOrderToConfirm ($order)
{
if ($order) {
Request::sendMessage([
'chat_id' => '#admin_username',
'text' => 'New Order registered',
'parse_mode' => 'HTML'
]);
}
}
But this does not work and does not anything.
Telegram bot API does not support sending messages using username because it's not a stable item and can be changed by the user. On the other hand, bots can only send messages to user that have sent at least one message to the bot before.
You know that when a user sends a message to a bot (for example the users taps on the start button) the bot can get his/her username and ChatID (As you know ChatID is different from username; ChatID is a long number) so I think the best way that you can fix this issue is storing the chat IDs and related usernames in a database and send the message to that chatID of your favorite username.
By the way, try searching online to see whether there is an API which supports sending messages to usernames or not. But as I know it's not possible.
This example works very well:
<?php
$token = 'YOUR_TOCKEN_HERE';
$website = 'https://api.telegram.org/bot' . $token;
$input = file_get_contents('php://input');
$update = json_decode($input, true);
$chatId = $update['message']['chat']['id'];
$message = $update['message']['text'];
switch ($message) {
case '/start':
$response = 'now bot is started';
sendMessage($chatId, $response);
break;
case '/info':
$response = 'Hi, i am #trecno_bot';
sendMessage($chatId, $response);
break;
default:
$response = 'Sorry, i can not understand you';
sendMessage($chatId, $response);
break;
}
function sendMessage($chatId, $response){
$url = $GLOBALS['website'] . '/sendMessage?chat_id=' . $chatId .
'&parse_mode=HTML&text=' . urlencode($response);
file_get_contents($url);
}
?>
Im using PayPal REST API with PHP, I have created a rest app in sandbox and everything as in documentation.
but it returns error
Got Http response code 401 when accessing https://api.sandbox.paypal.com/v1/oauth2/token.
not sure where Im going wrong on this, tried many other sample codes using rest api but same error everywhere.
can some one help me on this?
code is here
define('CLIENT_ID', 'MY CLIENT ID'); //your PayPal client ID
define('CLIENT_SECRET', 'MY SECRET'); //PayPal Secret
define('RETURN_URL', 'http://domain.com/order_process.php'); //return URL where PayPal redirects user
define('CANCEL_URL', 'http://domain.com/payment_cancel.html'); //cancel URL
define('PP_CURRENCY', 'USD'); //Currency code
define('PP_CONFIG_PATH', ''); //PayPal config path (sdk_config.ini)
include_once "vendor/autoload.php"; //include PayPal SDK
include_once "functions.inc.php"; //our PayPal functions
$item_name = 'Test Product'; //get item code
$item_code = 'sku123'; //get item code
$item_price = '10'; //get item price
$item_qty = '1'; //get quantity
/*
Note: DO NOT rely on item_price you get from products page, in production mode get only "item code"
from the products page and then fetch its actual price from Database.
Example :
$results = $mysqli->query("SELECT item_name, item_price FROM products WHERE item_code= '$item_code'");
while($row = $results->fetch_object()) {
$item_name = $row->item_name;
$item_price = item_price ;
}
*/
//set array of items you are selling, single or multiple
$items = array(
array('name'=> $item_name, 'quantity'=> $item_qty, 'price'=> $item_price, 'sku'=> $item_code, 'currency'=>PP_CURRENCY)
);
//calculate total amount of all quantity.
$total_amount = ($item_qty * $item_price);
try{ // try a payment request
//if payment method is paypal
$result = create_paypal_payment($total_amount, PP_CURRENCY, '', $items, RETURN_URL, CANCEL_URL);
//if payment method was PayPal, we need to redirect user to PayPal approval URL
if($result->state == "created" && $result->payer->payment_method == "paypal"){
$_SESSION["payment_id"] = $result->id; //set payment id for later use, we need this to execute payment
header("location: ". $result->links[1]->href); //after success redirect user to approval URL
exit();
}
}catch(PPConnectionException $ex) {
echo parseApiError($ex->getData());
} catch (Exception $ex) {
echo $ex->getMessage();
}
Ok, here is what I did:
Created a PayRequest
SetPaymentOptions - https://developer.paypal.com/webapps/developer/docs/classic/api/adaptive-payments/SetPaymentOptions_API_Operation/
ExecutePayment - "This payment request must be authorized by the sender". I have ran out of idea on why am I not able to execute the payment. From what I understand, once I execute the payment successfully, I will be given a payKey which I shall use this to redirect user to paypal. https://developer.paypal.com/webapps/developer/docs/classic/api/adaptive-payments/ExecutePayment_API_Operation/
Attached are the source codes that I used. The values are all hardcoded. I have tried my best to look through at similar questions, and it makes no sense to me as it contradicts what I understand. Some answers were pointing out that the buyer needs to approve the payment first before you executePayment.
I just want to see the details of all items when I reach the paypal login page.
//1. Obtain endpoint. For live, no need sandbox?
$endPoint = "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay";
//2. Format the HTTP headers needed to make the call.
$appID = "xxx"; //Sandbox test AppID:
$username = "xxx;
$password = "xxx";
$signature = "xxx";
$paypalHeaders = array(
"X-PAYPAL-SECURITY-USERID :" . $username,
"X-PAYPAL-SECURITY-PASSWORD :" . $password,
"X-PAYPAL-SECURITY-SIGNATURE :" . $signature,
"X-PAYPAL-APPLICATION-ID :" . $appID,
"X-PAYPAL-REQUEST-DATA-FORMAT : JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT : JSON"
);
$data = array();
$data['actionType'] = "CREATE"; //PAY
$data['currencyCode'] = "SGD";
$receiver['amount'] = $orderTotal;
$receiver['email'] = $receiverEmail;
$data['receiverList'] = array();
$data['receiverList']['receiver'][] = $receiver;
$data['returnUrl'] = $returnURL;
$data['cancelUrl'] = $cancleURL;
$requestEnvelope = array();
$requestEnvelope['errorLanguage'] = "en_US";
$data['requestEnvelope'] = $requestEnvelope;
//I omitted the POST call
//print_r($returnedData);
$payKey = $returnedData->payKey;
$paymentStatus = $returnedData->paymentExecStatus;
/*
* Set payment options
*/
$endPoint = "https://svcs.sandbox.paypal.com/AdaptivePayments/SetPaymentOptions";
//paymentDetailsData
$paymentDetailsData = array();
//set payKey
echo "payKey: " . $payKey;
$paymentDetailsData['payKey'] = $payKey;
//displayOptions
$displayOptions['businessName'] = "My Business";
$paymentDetailsData['displayOptions'] = $displayOptions;
//senderOptions
$senderOptions = array();
$senderOptions['requireShippingAddressSelection'] = true; //set to true if courier is chosen
$senderOptions['shippingAddress']['addresseeName'] = "Ny Name";
$senderOptions['shippingAddress']['street1'] = "Address 1Avenue 3";
$senderOptions['shippingAddress']['street2'] = "#xx-112";
$senderOptions['shippingAddress']['city'] = "Singapore";
$senderOptions['shippingAddress']['state'] = "Singapore";
$senderOptions['shippingAddress']['zip'] = "123456";
$senderOptions['shippingAddress']['country'] = "Singapore";
$paymentDetailsData['senderOptions'] = $senderOptions;
//item
$item = array();
$item['name'] = "Korea";
$item['itemPrice'] = 11;
//there is still price, and itemcount
//invoiceData
$invoiceData = array();
$invoiceData['item'] = $item;
//receiverOptions
$receiverOptions = array();
$receiverOptions['description'] = "Product description.";
$receiverOptions['invoiceData'] = $invoiceData;
$paypalEmail = "test#test.com"; //I may need to change this
$receiver['email'] = $paypalEmail;
$receiverOptions['receiver'] = $receiver;
$paymentDetailsData['receiverOptions'] = $receiverOptions;
//requestEnvelope. I have set the request envelope above. It is the same. Can still be used.
$paymentDetailsData['requestEnvelope'] = $requestEnvelope;
makePaypalCall($endPoint, $paypalHeaders, $paymentDetailsData);
/*
* Get payment options. I can see the result of get payment options correctly,
*/
echo "GETTING PAYMENT OPTIONS";
$endPoint = "https://svcs.sandbox.paypal.com/AdaptivePayments/GetPaymentOptions";
$getPaymentData['payKey'] = $payKey;
$getPaymentData['requestEnvelope'] = $requestEnvelope;
makePaypalCall($endPoint, $paypalHeaders, $getPaymentData);
$endPoint = "https://svcs.sandbox.paypal.com/AdaptivePayments/ExecutePayment";
/*
* ExecutePayment. Ok, I get the error here. This payment request must be authorized by the sender
*/
$executePaymentData = array();
echo "paykey: " . $payKey;
$executePaymentData['payKey'] = $payKey;
//$executePaymentData['actionType'] = "PAY";
$executePaymentData['requestEnvelope'] = $requestEnvelope;
I hope I understand you correctly.
To me it seems like you are skipping the step where the user needs to authorize the payment. When you do a Pay (Create) operation you should see get a RedirectURL in the response from PayPal. You need to redirect the user to this URL for them to authorize the payment on PayPal.
Once they have approved the payment, then you'll be able to execute the payment.
Your steps need to change to:
Create PayRequest
Set PaymentOptions
Redirect to PayPal (RedirectURL from the PayRequest response) for user authorization
If authorized, ExecutePayment
PayPal hints at this on the Pay API operation page
URL to redirect the sender's browser to after the sender has logged into PayPal and approved a payment; it is always required but only used if a payment requires explicit approval
After the step 3, the user will be returned to the URL your provided in $data['returnUrl'] = $returnURL;
I am using Delayed Chained Payment and often i end up with this error "This payment request must be authorized by the sender". Actually it was due to a small mistake in the logic.
wrong procedure (# step 3)
generate a payKey successfully
save it to database
refresh the page for some reason which results in generating new payKey (this new payKey doesn't update to database)
payRequest = pay();
.....
if(empty(db_record)) {
.....
db_record->payKey = payRequest->payKey;
db_record->save();
}
paid with new payKey ( ie. payment approved by sender)
trying to execute payment with payKey from database (which is indeed old one. That payKey was not used to make payment)
Solution
update database with last payKey which used for making payment by getting approval of sender
step 3 should be like
if(empty(db_record) || is_expired(db_record->payKey)) {
payRequest = pay();
.....
.....
db_record->payKey = payRequest->payKey;
db_record->save();
}
Im using the authorize.net recurring transaction.
What Im trying to do is give the an option to check off a donation if they want it recurring for the next 12 months.
So before the ARB - I want to verify the card but 0.00 isn't a valid amount. so if i made the amount 0.01 - how can I void the transaction after the card is verified?
Also - when a subscription is made I dont get an email from authorize.net telling me a transaction was made like when a regular transaction is processed.
My code:
$authorization = new AuthnetAIM($apilogin, $apitranskey, true);
$authorization->setTransaction($creditcard, $expiration, '0.01');
$authorization->setTransactionType('AUTH_ONLY');
$authorization->process();
if ($authorization->isApproved())
{
$subscription = new AuthnetARB($apilogin, $apitranskey, AuthnetARB::USE_DEVELOPMENT_SERVER);
// Set subscription information
$subscription->setParameter('amount', $amount);
$subscription->setParameter('cardNumber', $creditcard);
$subscription->setParameter('expirationDate', $expiration);
$subscription->setParameter('firstName', $business_firstname);
$subscription->setParameter('lastName', $business_lastname);
$subscription->setParameter('address', $business_address);
$subscription->setParameter('city', $business_city);
$subscription->setParameter('state', $business_state);
$subscription->setParameter('zip', $business_zipcode);
$subscription->setParameter('email', $email);
// Set the billing cycle for every three months
$subscription->setParameter('interval_length', 1);
$subscription->setParameter('startDate', date("Y-m-d", strtotime("+ 1 months")));
// Create the subscription
$subscription->createAccount();
// Check the results of our API call
if ($subscription->isSuccessful())
{
// Get the subscription ID
$subscription_id = $subscription->getSubscriberID();
Send_email();
}
else
{
$transError = 'your subscription was not created';
$hasError = true;
}
}
else if ($authorization->isDeclined())
{
$transError = 'This card is not valid';
$hasError = true;
}
}
catch (AuthnetARBException $e)
{
$transError = 'There was an error processing the transaction. Here is the error message:<br/> ';
echo $e->__toString();
$hasError = true;
}
}
With the new SDK for authorize this would work
$authorize = new AuthorizeNetAIM(self::AUTHNET_LOGIN, self::AUTHNET_TRANSKEY);
$authorize->setFields(array(
'amount' => '0.01',
'card_num' => $cardNumber,
'exp_date' => $expDate
));
$response = $authorize->authorizeOnly();
if ($response->response_code == 1) {
// good card
}else{
// bad card
}
Not only is 0.00 a valid amount, but if you're just trying to verify a credit card is legitimate you are required by Visa and Mastercard to use that amount. A few years ago they stopped allowing pre-auths of any real value to be done for this reason. I think there are fines for merchants who fail to do so.
Having said that, if you're going to take the "charge $.01 and then void the transaction" route, the following code should work:
$transaction_id = $authorization->getTransactionID();
$void = new AuthnetAIM($apilogin, $apitranskey, true);
$void->setTransactionType("VOID");
$void->setParameter('x_trans_id', $transaction_id);
$void->process();