Pay Dialogue를 열려고하는데 잘되지 않습니다. buy_credits 또는 ear_credits로 작업을 설정하면 작동합니다. 그러나 나는 그것이Facebook Pay Dialog가 resposnse를 반환하지 않습니다.
1383046 - Sorry, but we're having trouble processing your payment. You have not been charged for this transaction. Please try again.
내 자바 코드 "의 오류를 반환 buy_item하는 작업을 설정할 때
<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>
내 PHP 콜백 코드 :
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, '-_', '+/'));
}
내가 스크립트의 error_log 통화를 구매 버튼을 누르면 서비스를 두 번 호출하는 것처럼 보입니다. 동일한 메소드 호출 : payments_get_items. 응답 데이터가 올바르게 형식화 된 것 같습니다. 로그 결과는 다음과 같습니다.
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"}
HTTP 오류 코드가 없습니다. 응답 헤더가 잘 보입니다. Amazon EC2에서 IIS 7.5에서 콜백 코드를 호스팅하고 있었고 godaddy Linux 호스트로 이동하려고 시도했지만 동일한 오류가 발생했습니다. –
아직 답장을 보내지 않은 지불 콜백으로 인한 보고서를 아직 보지 못했습니다. 응답 확인은 지급 문서에 따라 유효합니다. 질문을하기 전에, 이것을 바꿔야한다 – Igy
내가 이것을 쓴 후에 그것을 바꿨다. 조금 더 추가하십시오. 나는 내가 스크립트를 볼 수 없었던 godaddy에서 콜백 스크립트를 가지고 있다는 것을 깨달았다. 이 코드는 godaddy linux 호스트에서 작동합니다. 임씨는 좀 더 파고를하고 PHP로 godaddy windows 호스트가 작동하는지 확인합니다. –