I'm using Apple Pay JS to integrate it into my website what should I sent onMerchantValidate - applepay

what I know so far is that I have to send a POST request to the apple server.
How or where can I get the merchIdentityCert cert and key??
NOTE: I'm going to send the post request from PHP
const options= {
url: endpointURL,
cert: merchIdentityCert,
key: merchIdentityCert,
method: 'post',
body:{
merchantIdentifier: "merchant.com.example.mystore",
displayName: "MyStore",
initiative: "web",
initiativeContext: "mystore.example.com"
},
json: true,
}

I figured how to connect to apple Servers and create the needed certificates for the POST request to work.
These steps must be done from a mac
Go to Apple Developer -> Create Certificate -> Apple Pay Merchant Identity
From your Mac go to KeyChain Access-> On the top right Select Keychain Access-> Certificate Assistant -> Request a Certificate From a Certificate Authority
Select Save to Disk & Let me specify key pair information
Key Size = 2048 bits / Algorithm = RSA
Upload the CSR to your Apple Pay Merchant Identity
Download the certificate given by Apple Pay and upload it to your Keychain Access
Export the certificate from Keychain Access as .p12 format
Open terminal direct it to the folder with the exported .p12 certificate
Run these commands
"openssl pkcs12 -in ApplePayMerchantIdentity_and_privatekey.p12 -out ApplePay.crt.pem -clcerts -nokeys"
"openssl pkcs12 -in ApplePayMerchantIdentity_and_privatekey.p12 -out ApplePay.key.pem -nocerts"
$path = "yourPath/ApplePay.crt.pem";
$path_key = "yourPath/ApplePay.key.pem";
// create a new cURL resource
$ch = curl_init();
$data = array(
"merchantIdentifier" => "Your merchant Name",
"displayName" => "Your Shop Name",
"initiative" => "web", // If you're going to use it on the web
"initiativeContext" => "Domain"
);
$data = json_encode($data);
$header = array(
'Content-Type: application/json'
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSLCERT, $path);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, ""); // For the Certificate Password
curl_setopt($ch, CURLOPT_SSLKEY, $path_key);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$serverOutput = curl_exec($ch);

Related

how to work locally with laravel when third-party api need only production IP to whitelist?

The scenario like this, I deployed my laravel app to heroku. The third-party api needs my production IP for whitelisting in order to use their resources. Heroku doesn't provide ip, I use add on to get ip. It connected ok between my app to third-party now. The problem is that, when I clone my app to local and start to run and test locally, it give error. (Undefined index: host) My code is below
$testparam = 'q='.$q.'&s='.$s;
$quotaguard_env = getenv("QUOTAGUARDSTATIC_URL");
$quotaguard = parse_url($quotaguard_env);
$proxyUrl = $quotaguard['host'].":".$quotaguard['port'];
$proxyAuth = $quotaguard['user'].":".$quotaguard['pass'];
$url = "http://xxxxx.com/api/resource";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxyUrl);
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth);
curl_setopt($ch, CURLOPT_POSTFIELDS,$testparam);
$response = curl_exec($ch);
$xml = simplexml_load_string($response);
$json = json_encode($xml);
$array = json_
decode($json,TRUE);
dd($array);
Currently, I have to push my file to heroku after I write one or two lines of code in order to see the result. Is there any way to write and test locally?
You need to set the QUOTAGUARDSTATIC_URL environment variable to what is in the QuotaGuard Admin dashboard or in Heroku's heroku config -a APPNAME command.

Cannot send iOS push notifications - 400 BadDeviceToken response

I have generated the .pem files for development using these commands in the Mac terminal:
openssl x509 -inform der -outform pem -in aps_development.cer -out PushNotificationAppCertificate.pem
openssl pkcs12 -in PushNotification.p12 -out PushNotificationAppKey.pem -nocerts
cat PushNotificationAppCertificate.pem PushNotificationAppKey.pem > PushNotificationAppCertificateKey.pem
And on the server I use PHP:
$curl = curl_init();
$device_token = "oVVEyzOm8LYn1nEYQLUcp1nBQw+UKHUeJbVHxcqr3ls=";
$pem_file = "PushNotificationAppCertificateKey.pem";
$pem_secret = "<password>";
$apns_topic = "<myapp.id>";
$sample_alert = '{"aps":{"alert":"hi","sound":"default"}}';
$url = "https://api.development.push.apple.com/3/device/".urlencode($device_token);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_PORT, 443);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sample_alert);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("apns-topic: $apns_topic"));
curl_setopt($ch, CURLOPT_SSLCERT, $pem_file);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $pem_secret);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
However, BadDeviceToken is the response, and I am not getting the notification on the device.
According to the Apple documentation, either the device token is invalid, or I am using production certificate for the development server or vice versa; neither of which are the case here.
How can I make this work?
I solved it.
The problem was with the device token - if you knew, how they should look like, you would instantly tell it was not acquired the right way. It is not supposed to contain = or + characters, and its length should be 64 characters.
In my RegisteredForRemoteNotifications() function (Xamarin.iOS) I had used the
deviceToken.GetBase64EncodedString(NSDataBase64EncodingOptions.None)
function to get the token in string form. But the correct procedure is
byte[] bytes = deviceToken.ToArray<byte>();
string[] hexArray = bytes.Select(b => b.ToString("x2")).ToArray();
string tokenString = string.Join(string.Empty, hexArray);

InvalidAuthenticationToken when uploading file to OneDrive

I am trying to upload a file to OneDrive using the following code:
$graph_url = 'https://graph.microsoft.com/v1.0/me/drive/root:/filename:/createUploadSession';
$file = file_get_contents('logo.jpeg');
$headers = [
'Content-Type: json',
"Cache-Control: no-cache",
"Pragma: no-cache",
"Authorization: bearer EwAQA61DBAAUcSSzoTJJsy+XrnQXgAKO5cj4yc8AAewWnvfTuLAC2gDmYesGiVawqeIpfS8lJjyCyeXQMrKOu92FA0SK12N/87GBTs4ba2LJ5buqmm9gX18by0jPWzZ5qvpc+BdfMC2wUyiMYxh8QH8BJFBctAVgSaKM1KmhA8mAwb2czyw4OeWdupKH7qSPvjRtwBTTxxX8iIO3IeNbpXDghri9MWRGyVIffGf2Oi+RzQm5jbGuDtXrQa4K80m1o8PHcEkdIEXbaAgIE8oBYCVBQ7fyYxA84b0NjghSRbCZDj5rVbo1MDeBv0J4inmPthEbAMcS3fRSBdFs3+SSz+jZwb3SgSp5Q+VXiRs+keDQHspaoSNt4Ho0+pX94WQDZgAACAk/KNYU0yEY4AHihrs84QKvmWWfIOTYCBudQZD7tKp2ZeOpXEI7q3tOTuwHTv7uUmYxkpGswiNSeW2r9DEBdQ5gBtZ/YCXMPhlBLSxxahrl816zsj/UDi2c6dmB+6J1wk60/hm1Ll6vqn8YbtlyQh9hFLpWejo8+Vofh5/kRUfUSl1v7FIP7YIJLvTyNn1gGy9IMnxYdvba9ACGotVpFTAMNdjz6aQwUk4MJjD7csqYVpyMBh8O7bS40dRMjiUkdhXYvA03L/JV818qgo0W0uwJmoqzPJfe7VB+VekqxPCyVT6A86y/OaD1EsTaLwBILG8eS48Odr/qg7azjUsrdryS+rg7wfQEBEL+kIkS5Ne8eTg1/t2aAXFsUukiIBkTYp+Sold4yhqJU2w/cRDZiz9m3GBltjTS+JiIX2Ll0ABbOwmY9pkc6O8/3T0ZhgVuIigfIILTdMGMu9sNvJtVxYL4gbRlNX+gyMBHZHDo2zktdD5l4vDa+TTgn2Fc3CDUli/qLU1UX2SfJ6+B+epmX/wA32cXVtfDPcm605c18LipDoOVGxzf9RVyNe9e3VCFvR9UBmkobodVfE1VhUfzw/s5CHrjzCZ7ZZDt84Hm6VoWIVZLtYueHCuAaEhLa0gWZTKUSwvu3hCDwZUaAg==",
"Content-Length: ".filesize('logo.jpeg'),
];
$ch = curl_init($graph_url);
curl_setopt($ch, CURLOPT_URL, $graph_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{}');
$server_output = curl_exec($ch);
$info = curl_getinfo($ch);
The result, however, is the always the following error:
"error": {
"code": "InvalidAuthenticationToken",
"message": "CompactToken parsing failed with error code: 8004920A",
"innerError": {
"request-id": "bab6035c-17c5-45ea-99ac-7c809e446ca2",
"date": "2018-12-22T09:42:03"
}
}
First of all, it seems like your token is incorrect. So step 1 is verify the token is correct. You can do that by copying your token and pasting it on the website Microsoft created specifically for this job. https://jwt.ms
Secondly as the microsoft documentation describes you have 2 ways of uploading a file to onedrive.
Direct upload (only for small files) docs
Through a upload session, docs
You're trying to do a direct upload to the CreateUploadSession endpoint.
The first way works (for small files) by uploading the file to the /content endpoint, but that is just a file only upload. So no content headers with json in them.
The second way works by creating an upload sessions (that responds with some json) and then do a second request for uploading the file to the endpoint you got from the url.
The documentation on these things are quite clear, and I think you're using PHP, so it should be easy to mimic the provided curl requests with php.

Yahoo Oauth 2 PHP

I'm working on a project where i need to fetch contacts from yahoo mail. and I'm using Oauth2.0. I'm getting access_token and all things from here https:// api.login.yahoo.com/oauth2/get_token via curl with passing grant_type and all required parameters which is fine. but the problem is refresh_token and xoauth_yahoo_guid from yahoo I'm redirecting to this url https://social.yahooapis.com/v1/user/{xoauth_yahoo_guid}/contacts?format=json. I'm getting this output:-
{"error":{"#lang":"en-US","#uri":"http://yahoo.com","description":"Not Authorized - Either YT cookies or a valid OAuth token must be passed for authorization","detail":"Not Authorized - Either YT cookies or a valid OAuth token must be passed for authorization"}}
However I'm working in codeigniter and i need this task to be done in ajax or javascript But I've tried a lot but unfortunately nothing worked out for me. Please help me to get rid out of this problem.
Thanks.
Finally I got the answer. I just have to send the header
$headers= array(
'Authorization: Bearer '.< access_token >,
'Accept: application/json',
'Content-Type: application/json'
);
with following Code:-
$ch = curl_init();
$url = "https://social.yahooapis.com/v1/user/me/contacts?format=json";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$output3 = curl_exec ($ch);
curl_close ($ch); // close curl handle
$finalresult = json_decode($output3);
echo'<pre>';print_r($finalresult);

Piping emails from postfix under Plesk to Ostickets helpdesk

I'm trying to pipe support emails from my production mail server (Plesk 12 and Postfix) to send them to another VPS hosting my helpdesk installation, I have chosen ostickets helpdesk for many reasons (Open source,PHP/MySQL...)
So, the idea is to trigger email reception on some adresses such as contact#company.com, support#company.com... then resend them to ostickets via its API in order to create a new ticket there.
I tried this way
http://blog.absolutedisaster.co.uk/osticket-plesk-9-postfix-pipe-mail-to-a-progr/
It explains how to create a pipe to trigger email, lunch php script ...etc
Because of some permission issues, I kept all this configuration and change just the last thing : php script
So I've replaced this php script by a simple bash script doing the same thing : send a request to API to create a new ticket via CURL.
Now In my production mail server the pipe is recognized and the email is trigged successfully :
The same in the other side, osticket API is receiving the request:
The problem is that the http response is 400 as you can see, which means ans error code #66 in ostickets (malformed email).
So, I think the problem is in my bash script :
exec curl --header 'X-API-Key: API_KEY_HERE' --user-agent 'osTicket API Client v1.7' --data - 'http://support.company.com/api/tickets.email'
the original PHP script I have replaced by this is :
#!/usr/bin/php -q
<?php
# Configuration: Enter the url and key. That is it.
# url => URL to api/tickets.email e.g http://yourdomain.com/support/api/tickets.email
# key => API's Key (see admin panel on how to generate a key)
#
$config = array(
'url'=>'http://support.company.com/api/tickets.email',
'key'=>'API_KEY_HERE'
);
#pre-checks
function_exists('file_get_contents') or die('upgrade php >=4.3');
function_exists('curl_version') or die('CURL support required');
#read stdin (piped email)
$data=file_get_contents('php://stdin') or die('Error reading stdin. No message');
#set timeout
set_time_limit(10);
#curl post
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.7');
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key']));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
curl_close($ch);
//Use postfix exit codes...expected by MTA.
$code = 75;
if(preg_match('/HTTP\/.* ([0-9]+) .*/', $result, $status)) {
switch($status[1]) {
case 201: //Success
$code = 0;
break;
case 400:
$code = 66;
break;
case 401: /* permission denied */
case 403:
$code = 77;
break;
case 415:
case 416:
case 417:
case 501:
$code = 65;
break;
case 503:
$code = 69;
break;
case 500: //Server error.
default: //Temp (unknown) failure - retry
$code = 75;
}
}
exit($code);
?>
What is missing in my bash script ? (especially the stdin input)
thank you so much,
UPDATE
The problem was indeed in the bash script, here is the solution I came up with:
#!/bin/bash
data=`cat -`
exec curl --header 'X-API-Key: API_KEY_HERE' --user-agent 'osTicket API Client v1.7' --data "$data" 'http://support.company.com/api/tickets.email'
The problem was indeed in the bash script, here is the solution I came up with:
#!/bin/bash
data=`cat -`
exec curl --header 'X-API-Key: API_KEY_HERE' --user-agent 'osTicket API Client v1.7' --data "$data" 'http://support.company.com/api/tickets.email'

Resources