I am testing in app purchase with MKStoreKit.
I'm getting response's status 21002 and wonder why.
Do I need to set up a certificate or something to talk to apple server?
Below is the php code that MKStoreKit uses
<?php
$devmode = TRUE; // change this to FALSE after testing in sandbox
$receiptdata = $_POST['receiptdata'];
$udid = $_POST['udid'];
if($devmode)
{
$appleURL = "https://sandbox.itunes.apple.com/verifyReceipt";
}
else
{
$appleURL = "https://buy.itunes.apple.com/verifyReceipt";
}
$receipt = json_encode(array("receipt-data" => $receiptdata));
$response_json = do_post_request($appleURL, $receipt);
$response = json_decode($response_json);
file_put_contents('php://stderr', print_r($response->{'status'}, true));
file_put_contents('php://stderr', print_r($udid, true));
if($response->{'status'} == 0)
{
file_put_contents('php://stderr', print_r("yes", true));
error_log('udid: %s', $udid);
error_log('quantity: %d', $response->{'receipt'}->quantity);
echo ('YES');
}
else
{
echo ('NO');
}
function do_post_request($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = #fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = #stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
?>
Please check Verify Purchase
MKStore Kit has a bug with sending receiptdata to server
You should base64 encode receiptData not asciiStringEncoding.
Used the following link's code to base64 and I get status 0.
Verify receipt for in App purchase
Related
How can i get customer Email in return URL after making payment using PayPal button?
Thanks.
<?php
if(isset($_GET['tx']))
{
$tx = $_GET['tx'];
$your_pdt_identity_token = //token
$request = curl_init();
// Set request options
curl_setopt_array($request, array
(
CURLOPT_URL => 'https://www.sandbox.paypal.com/cgi-bin/webscr', //sandbox!!!
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => http_build_query(array
(
'cmd' => '_notify-synch',
'tx' => $tx,
'at' => $your_pdt_identity_token,
)),
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HEADER => FALSE,
// CURLOPT_SSL_VERIFYPEER => TRUE,
// CURLOPT_CAINFO => 'cacert.pem',
));
// Execute request and get response and status code
$response = curl_exec($request);
$status = curl_getinfo($request, CURLINFO_HTTP_CODE);
// Close connection
curl_close($request);
}
if($status == 200 AND strpos($response, 'SUCCESS') === 0)
{
$singlequantity = explode("\n",$response);
$email = $singlequantity[15];
$count = null;
$email = preg_replace('"%40"', '#', $email, -1, $count);
preg_match("/payer_email=(.*)/", $email, $email);
}
else
{
echo '<script type="text/javascript">
window.location="cancel.php";
</script>';
}
?>
i know i shoved it in real hard right now , but this might be useful to other users attempting to do this.
I'm trying to use the facebook php api to rsvp users to a public event.
So far I can only get it to work for users who have already been invited.
I've tried:
$path = $event_id.'/attending';
$method = 'POST';
try
{
$this->facebook->api($path, $method);
}
catch(FacebookApiException $e){}
Which does nothing.
My code as it stands is:
function rsvpEvent($event_id)
{
$fb_config = array(
'appId' => APP_ID,
'secret' => APP_SECRET,
'cookie' => true,
);
$this->load->library('facebook', $fb_config);
$me = $this->facebook->api('/me/');
$user_id = $me['id'];
$path = $event_id.'/invited/'.$user_id;
$status = $this->facebook->api($path, 'GET');
$status = $status['data'][0]['rsvp_status'];
if($status === 'not_replied')
{
$path = $event_id.'/attending';
$method = 'POST';
try
{
$this->facebook->api($path, $method);
}
catch(FacebookApiException $e){}
}
}
Has anyone got any ideas how I can get this to work?
$path = $event_id.'/attending?access_token='.$SOME_ACCESS_TOKEN;
You're not using the access token in your code, so I am uncertain of whether you skipped it when you copied it, If it's not in the code, then it may be that.
I retrieved the information here
i run a cloud app (using CakePHP) on Rackspace and i wanna send emails using cakephp.
I used this: https://github.com/kochb/cakephp-mailgun
but it returns me an
"Could not send email.
Error: An Internal Error Has Occurred."
error.
The way i try to send an email is with the following code:
$Email = new CakeEmail();
$from = $this->request->data['Mail']['from'];
$to = ($this->request->data['Mail']['to']);
$subject = $this->request->data['Mail']['subject'];
$message = $this->request->data['Mail']['message'];
$Email->sender($from, 'TestName');
$Email->from($from)
->bcc($to)
->replyTo($from)
->subject($subject)
->send($message);
$this->Session->setFlash('On the way to recipient');
$this->redirect(array('action' => 'index'));
I have edited the Config/Email.php file inserting the MailGun API credentials etc.
What's possibly going on? Can you find out why this happens?
Thanks in advance!
(I was having the same errors you were)
The BasicTransport didn't have the right "pre-processing" nor the appropriate response handling.
I copied over the functionality from CurlTransport and it works for me now.
Specifically, we needed:
$post = array();
$post_preprocess = array_merge(
$email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject')),
array(
'text' => $email->message(CakeEmail::MESSAGE_TEXT),
'html' => $email->message(CakeEmail::MESSAGE_HTML)
)
);
foreach ($post_preprocess as $k => $v) {
if (! empty($v)) {
$post[strtolower($k)] = $v;
}
}
and then:
$response = $http->post($url, $post, $request);
if ($response === false) {
throw new SocketException("Mailgun BasicTransport error, no response", 500);
}
$http_status = $response->code;
if ($http_status != 200) {
throw new SocketException("Mailgun request failed. Status: $http_status, Response: {$response->body}", 500);
}
I would like to retrieve all accounts datas and contact datas in Sugarcrm database using webservice .
I would like it to show it in a webpage .
How can i go about it?
Modify the below code to your requirements. It uses the SOAP API of SugarCRM.
$user_name = 'admin';
$user_password = 'admin';
$sugarcrm_url = 'http://example.com/'
$options = array(
"uri" => $sugarcrm_url,
"trace" => true
);
$offset = 0;
$limit = 100;
try {
$client = new SoapClient($sugarcrm_url.'service/v4_1/soap.php?wsdl', $options);
$response = $client->__soapCall('login',array(
'user_auth'=>array(
'user_name'=>$user_name,
'password'=>md5($user_password),
'version'=>'.01'
),
'application_name'=>'SoapTest'
));
$session_id = $response->id;
$response = $client->__soapCall('get_entry_list',array(
'session'=>$session_id,
'module_name'=>'Contacts',
'query'=>'',
'order_by'=>'contacts.last_name asc',
'offset'=>$offset,
'select_fields'=>array(),
'max_results'=>$limit)
);
print_r($response);
$response = $client->__soapCall('get_entry_list',array(
'session'=>$session_id,
'module_name'=>'Accounts',
'query'=>'',
'order_by'=>'accounts.name asc',
'offset'=>$offset,
'select_fields'=>array('id', 'name', 'email1'),
'max_results'=>$limit)
);
print_r($response);
$response = $client->__soapCall('logout',array('session'=>$session_id));
} catch (Exception $ex) {
echo $ex->getMessage();
}
I'm trying to open a Pay Dialog and it's not going well. When I set the action to buy_credits or ear_credits it works. But when I set action to buy_item it returns an error of"
1383046 - Sorry, but we're having trouble processing your payment. You have not been charged for this transaction. Please try again.
My Java Code:
<script type="text/javascript">
function buy() {
FB.ui(
{
method: 'pay',
action: 'buy_item',
order_info: { 'item_id': '1a'},
dev_purchase_params: {'oscif': true}
},
js_callback);
}
var js_callback = function (data) {
if (data['order_id']) {
write_callback_data(
"<br><b>Transaction Completed!</b> </br></br>"
+ "Data returned from Facebook: </br>"
+ "Order ID: " + data['order_id'] + "</br>"
+ "Status: " + data['status']);
} else if (data['error_code']) {
// Appropriately alert the user.
write_callback_data(
"<br><b>Transaction Failed!</b> </br></br>"
+ "Error message returned from Facebook:</br>"
+ data['error_code'] + " - "
+ data['error_message']);
} else {
// Appropriately alert the user.
write_callback_data("<br><b>Transaction failed!</b>");
}
};
function write_callback_data(str) {
document.getElementById('fb-ui-return-data').innerHTML = str;
}
</script>
My PHP callback code:
error_reporting(E_ALL);
$app_secret = '********************************';
// Validate request is from Facebook and parse contents for use.
$request = parse_signed_request($_POST['signed_request'], $app_secret);
// Get request type.
// Two types:
// 1. payments_get_items.
// 2. payments_status_update.
$request_type = $_POST['method'];
error_log($request_type, 0);
// Setup response.
$response = '';
if ($request_type == 'payments_get_items') {
// Get order info from Pay Dialog's order_info.
// Assumes order_info is a JSON encoded string.
$order_info = json_decode($request['credits']['order_info'], true);
// Get item id.
$item_id = $order_info['item_id'];
// Simulutates item lookup based on Pay Dialog's order_info.
if ($item_id == '1a') {
$item = array(
'title' => '100 Gold',
'description' => 'Premium Currency.',
// Price must be denominated in credits.
'price' => 5,
'image_url' => '1a.png'
);
// Construct response.
$response = array(
'content' => array(
0 => $item,
),
'method' => "payments_get_items",
);
// Response must be JSON encoded.
$response = json_encode($response);
}
} else if ($request_type == "payments_status_update") {
// Get order details.
$order_details = json_decode($request['credits']['order_details'], true);
// Determine if this is an earned currency order.
$item_data = json_decode($order_details['items'][0]['data'], true);
$earned_currency_order = (isset($item_data['modified'])) ?
$item_data['modified'] : null;
// Get order status.
$current_order_status = $order_details['status'];
if ($current_order_status == 'placed') {
// Fulfill order based on $order_details unless...
if ($earned_currency_order) {
// Fulfill order based on the information below...
// URL to the application's currency webpage.
$product = $earned_currency_order['product'];
// Title of the application currency webpage.
$product_title = $earned_currency_order['product_title'];
// Amount of application currency to deposit.
$product_amount = $earned_currency_order['product_amount'];
// If the order is settled, the developer will receive this
// amount of credits as payment.
$credits_amount = $earned_currency_order['credits_amount'];
}
$next_order_status = 'settled';
// Construct response.
$response = array(
'content' => array(
'status' => $next_order_status,
'order_id' => $order_details['order_id'],
),
'method' => $request_type,
);
// Response must be JSON encoded.
$response = json_encode($response);
} else if ($current_order_status == 'disputed') {
// 1. Track disputed item orders.
// 2. Investigate user's dispute and resolve by settling or refunding the order.
// 3. Update the order status asychronously using Graph API.
} else if ($current_order_status == 'refunded') {
// Track refunded item orders initiated by Facebook. No need to respond.
} else {
// Track other order statuses.
}
}
// Send response.
error_log(print_r($response, true));
echo $response;
// These methods are documented here:
// https://developers.facebook.com/docs/authentication/signed_request/
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
I have error_log calls in the script and it seems when I press the buy button it calls the service twice. Calling the same method: payments_get_items. The response data looks like it is properly formatted. Here is the output of the log:
payments_get_items
{"content":[{"title":"100 Gold","description":"Premium Currency.","price":5,"image_url":"1a.png"}],"method":"payments_get_items"}
payments_get_items
{"content":[{"title":"100 Gold","description":"Premium Currency.","price":5,"image_url":"1a.png"}],"method":"payments_get_items"}
This is almost certainly a problem with the response your callback URL is returning to Facebook.
The reason you see two entries is that Facebook will try twice to get a (valid) response before failing, and giving the user the 'Sorry, but we're having trouble processing your payment...' error message.
Check the HTTP error codes and the body of the response you're giving to Facebook and make sure it's valid