I'm fetching a Webhook that is coming from Braintree. The Webhook is return a success and also creates the log file. This is the code I'm using:
if( isset($_POST["bt_signature"]) && isset($_POST["bt_payload"])){
$webhookNotification = \Braintree_WebhookNotification::parse(
$_POST["bt_signature"], $_POST["bt_payload"]
);
$message = "[Webhook Received "
. $webhookNotification->timestamp->format('Y-m-d H:i:s') . "] "
. "Kind: " . $webhookNotification->kind . " | "
. "Payment ID: " . $webhookNotification->localPaymentCompleted->paymentId . "\n";
file_put_contents("/tmp/webhook.log", $message, FILE_APPEND);
// if everything went fine, send confirmation to the buyer
$this->artikelRepository->sendConfirmationAction(null, $webhookNotification->localPaymentCompleted->paymentId);
}
To confirm the payment I need the paymentId of the local payment. I tried with various methods, but this should work: $webhookNotification->localPaymentCompleted->paymentId according to the test file.
The log file returns this, though:
How am I able to retrieve the Payment ID of a local payment inside the webhook function?
Update: I just noticed that we used a totally outdated SDK. The functions we tried to use were not even added in the old version.
Related
My QuickBooks Online Application needs to create a Service Item in a QuickBooks Account.
When creating a Service Item through QBO API, I need to query the account for ExpenseAccountRef.Name, ExpenseAccountRef.Value, IncomeAccountRef.Name and IncomeAccountRef.Value first. How can this be done?
I have tried running the following query first but it simply:
$table = "Account";
$entities = $dataService->Query("Select * from $table");
$error = $dataService->getLastError();
if ($error) {
echo "The Status code is: " . $error->getHttpStatusCode() . "\n";
echo "The Helper message is: " . $error->getOAuthHelperError() . "\n";
echo "The Response message is: " . $error->getResponseBody() . "\n";
exit();
}
But it does not provide any of the fields I need listed above.
The user has an email with a link from my organisation.
This link goes direct to my account https://mdepayments.epdq.co.uk/ncol/test/
i.e. it does not reference my organisation's website first.
This is all on the Test environment not Live (real money).
I am trying to use parameters after the url as html email may sometimes not be allowed by a user.
I've not found example code on how to do this.
I was given some pseudo code originally from EPDQ.
Sample url
https://mdepayments.epdq.co.uk/ncol/test/orderstandard.asp?
amount=12500&
CURRENCY=PND&
LANGUAGE=en_US&
OrderID=order123_001&
PSPID=XXXXX
SHASIGN=XXXX0C75B23EDBAE523E165176882C19BEACB7E7DEB38955224186BC66C2678FEEA4E4CA2512789001CC7A4E68XXXX3EFD35242BFEFBB7B1D4D7E19CBE80XXXX
(SHASIGN some chars changed to XXXX &PSPID changed to XXXXX for security)
Webpage result
<--------start---------->
Payment confirmation
>
> Order reference : order123_001 Total charge : --- Beneficiary
> : ---
>
> An error has occurred; please try again later. If you are the owner or
> the integrator of this website, please log into the Barclaycard back
> office to see the details of the error.
<--------end--------->
I used this code to generate the SHA
<?php
//- integration user details - //
$PW ="16char_SHA_code";
$PSPID = "XXXXX";
$OrderID ="order123_001";
$PaymentAmount =12500;
$CurrencyCode ="GBP";
$DigestivePlain =
"AMOUNT=" . $PaymentAmount . $PW .
"CURRENCY=" . $CurrencyCode . $PW .
"LANGUAGE=en_US" . $PW .
"ORDERID=" . $OrderID . $PW .
"PSPID=" . $PSPID . $PW .
"";
$strHashedString_plain = strtoupper(hash('sha512',($DigestivePlain)));
print $strHashedString_plain;
?>
I have a working HTML form which goes through my organisation website. It allows the user to enter details and a successful payment is made by EPDQ.
$DigestivePlain is based on a EPDQ example and works on my HTML form.
This PHP is to generate the SHASIGN
<?php
//- integration user details - //
$PW ="MyShaInPassPhrase";
$PSPID = "MyPSPID";
$OrderID ="order123_001";
$PaymentAmount =12500;
$CurrencyCode ="GBP";
//important to order alphabetically
$DigestivePlain =
"AMOUNT=" . $PaymentAmount . $PW .
"CURRENCY=" . $CurrencyCode . $PW .
"LANGUAGE=en_US" . $PW .
"ORDERID=" . $OrderID . $PW .
"PMLISTTYPE=2". $PW .
"PSPID=" . $PSPID . $PW .
"";
$strHashedString_plain = strtoupper(hash('sha512',($DigestivePlain)));
print $strHashedString_plain;
?>
Now the url
PSPID: 5 character PSPID (not XXXXX)
SHASIGN - created by php code above 128 characters (not YYYY...)
https://mdepayments.epdq.co.uk/ncol/test/orderstandard.asp
?AMOUNT=12500&CURRENCY=GBP&LANGUAGE=en_US&ORDERID=order123_001&PMLISTTYPE=2&PSPID=XXXXX&
SHASIGN=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
This took me to the EPDQ Card selection screen and then on to the payments screen and a successfull transaction.
I am writing plugin which sends coupon code for every X spent at shop and this feature works pretty well but I have troubles with sending coupon to a new registered user.
Sending mail function (XYZ here on purpose):
function sendFirstVoucher($to_email, $discount, $name, $coupon){
$headers = 'From: XYZ' . "";
$subject = 'Your ' . $discount . '% discount voucher for XYZ';
$message = 'Hi . ' . $name . 'and thank you for registering with XYZ! \r\n\r\n' .
"blah blah blah " . $coupon . " when you check out on our website, you can apply the code in either the cart page or check out page. \r\n\r\n" .
"From now on when you make purchases you will also receive additional discount codes for every $100 spent. More information can be found at our website (link to membership program page). \r\n" .
"If you have any questions please feel free to contact us at XYZ \r\n\r\n" .
"Kind Regards, \r\nThe XYZ";
wp_mail($to_email, $subject, $message, $headers);
}
And in the main plugin file:
function send_coupon_to_freshly_registered_user($customer_id, $new_customer_data, $password_generated) {
$coupon_code = generateCoupon(5);
$user_email = $new_customer_data["user_email"];
$user_login = $new_customer_data["user_login"];
sendFirstVoucher($user_email, "5", $user_login, $coupon_code);
}
finally at the nearly end of file there is:
add_action('woocommerce_created_customer', 'send_coupon_to_freshly_registered_user',10,3);
But once I am creating user via dashboard or register myself via wp-login page (because site is in maintenace mode) it's not sending any email nor creating coupon (it works perfectly for similar function for X voucher per 100$)
Have anyone got idea how to acomplish this?
Kind regards,
Tom
Ok, I have achieved this by using core wp functions:
add_action('user_register', 'send_coupon_to_freshly_registered_user',10,1);
function send_coupon_to_freshly_registered_user($user_id) {
$user = get_user_by('id',$user_id); //new line
$user_login = stripslashes($user->user_login); //changed line
$user_email = stripslashes($user->user_email); //changed line
$coupon_code = generateCoupon(5);
sendFirstVoucher($user_email, "5", $user_login, $coupon_code);
}
I hope it will help someone. Maybe it's not a real answer but the one that works for me.
Regards,
Tom
I create a new payment gateway in cscart. After get success result from payment gateway cs cart redirect it to checkout page and show incomplete checkout.Please help me to solve this issue.
Because you did not provide any code, I made an example code for processing the response:
if ($mode == 'return') {
// this means, that the payment processor returned from 3rd party checkout page
$order_info = fn_get_order_info($_REQUEST['order_id'], true);
// you should have a response code (this section depends on your payment gateway)
if ($_REQUEST['response_code'] == "S") {
// the transaction was successful!
$pp_response['order_status'] = 'P';
$pp_response['transaction_id'] = $_REQUEST['transaction_id'];
$pp_response["reason_text"] = $_REQUEST['response_code'] . ": " . $_REQUEST['transaction_id']);
fn_finish_payment($_REQUEST['order_id'], $pp_response, false);
fn_order_placement_routines('route', $_REQUEST['order_id']);
} else {
// the transaction was NOT successful!
$pp_response['order_status'] = 'N';
$pp_response['transaction_id'] = $_REQUEST['transaction_id'];
$pp_response["reason_text"] = $_REQUEST['response_code'] . ": " . $_REQUEST['transaction_id']);
fn_order_placement_routines('route', $_REQUEST['order_id'], false);
}
}
The key "functions" are: fn_finish_payment() and fn_order_placement_routines(). If you did not finish the payment, you will be redirected to the checkout page, because this means, something went wrong.
Anyone know the proper way to authenticate and publish directly to a calendar without relying on a currently logged in user? Several weeks ago I built a calendar that used the standard Oauth 2.0 protocol but this relied sessions stored by a user's we browser. I have one calendar that I want to pass events to from an application I am writing with a basic PHP framework. I'm more concerned with what are the best practices that others are using. Your answer could be simply, don't do it. Thanks alot.
Use OAuth 2 and the Authorization Code flow (web server flow), with offline enabled. Store the refresh tokens (which last indefinitely until the user has revoked), and you'll be able to upload events to Google Calendar even when the user isn't currently logged in.
More info:
https://developers.google.com/accounts/docs/OAuth2WebServer#offline
try Zend_Gdata_Calendar with this library you are able to insert or get events from any user(with the right username and password obviously) from google calendar and integrate with your own calendar or display it..here a short example:
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient('gmail#user.com', 'gmailpassword', $service);
$service = new Zend_Gdata_Calendar($client);
$query = $service->newEventQuery();
$query->setUser('default');
$query->setVisibility('private');
try {
$eventFeed = $service->getCalendarEventFeed($query);
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getMessage();
}
echo "<ul>";
foreach ($eventFeed as $event) {
echo "<li>" . $event->title . " (Event ID: " . $event->id . ")</li>";
}
echo "</ul>";
$eventURL = "http://www.google.com/calendar/feeds/default/private/full/Dir0FthEpUbl1cGma1lCalendAr";
try {
$event = $service->getCalendarEventEntry($eventURL);
echo 'Evento: ' . $event->getTitle() .'<br>';
echo 'detalles: ' . $event->getContent().'<br>';
foreach ($event->getWhen() as $dato)
{
echo 'inicia: ' . substr($dato->startTime, 0,-19) . ' a las: ' . substr($dato->startTime, 11,-10) .'<br>';
echo 'termina: ' .substr($dato->endTime,0,-19) . ' a las: ' . substr($dato->endTime,11,-10) .'<br>';
}
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getMessage();
}
with this you can add, update, edit or delete events from calendar form any user with mail and password...