私はPayPalのREST APIに統合されたPHPアプリケーションを開発中です。私はトランザクションを正しく処理し、トランザクションIDをMySQLデータベースに保存しています。私は現在販売を払い戻ししようとしていますが、「着信JSON要求がAPIリクエストにマップされていません」というエラーを返すことを止めることはできません。誰かがこれを得る方法についてのアドバイスを持っていますか?PHP PayPal REST APIを使用して払い戻しを行いますか?
私はコードの中に、その結果に関するコメントを残しました。私はこの作業をする方向で少し失われている気がします。どんな助けもありがとう。
私はここにあるドキュメントを、次のしてきた: https://developer.paypal.com/docs/integration/direct/payments/refund-payment/
私はPHPにその要求を適応に苦労することができます。
私はこのコードのビットが見つかりました:
https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/payments/RefundCapture.php
しかし、それは簡単な返金要求のためにビット過剰に思われるファイルのツリーを「必要」されます。<?php
require_once(dirname(__FILE__) . '/paypalSDK/autoload.php'); // require paypal files
require_once(dirname(__FILE__) . '/paypalSDK/paypal/rest-api-sdk-php/sample/common.php'); // require paypal files
// call required stuff
use PayPal\Api\Address;
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\ExecutePayment;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\PaymentCard;
use PayPal\Api\PaymentExecution;
use PayPal\Api\Transaction;
use PayPal\Api\Capture;
use PayPal\Api\Refund;
use PayPal\Api\RefundRequest;
use PayPal\Api\Sale;
$orderID = $_GET['order_id']; // order ID we wish to refund
// pull the details from the database so we have the transaction refund ID
$refQ = mysql_query("SELECT * FROM orders WHERE orders_ID = $orderID", $db);
$refC = mysql_num_rows($refQ);
if(!empty($refC)){
$refR = mysql_fetch_assoc($refQ);
$refNumber = $refR['orders_transaction_ref']; // paypal transaction ID
$FinalTotal = $refR['orders_order_total']; // order total
// paypal credentials
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'abc',
'xyz'
)
);
$apiContext->setConfig(array('mode' => 'live',)); // live use, not sandbox
//$amount = new Amount(); // commenting these out seemingly has no effect
//$amount->setCurrency("USD") // commenting these out seemingly has no effect
// ->setTotal($FinalTotal); // commenting these out seemingly has no effect
$refund = new Refund(); // if I comment these 2 lines out, I get "refund cannot be null"
$refund->setAmount($FinalTotal); // if I comment these 2 lines out, I get "refund cannot be null"
$sale = new Capture(); // if I comment these 2 lines out, I get "Call to a member function refund() on a non-object"
$sale->setId($refNumber); // if I comment these 2 lines out, I get "Call to a member function refund() on a non-object"
$refundRequest = new RefundRequest(); // commenting these out seemingly has no effect
$refundRequest->setAmount($FinalTotal); // commenting these out seemingly has no effect
//$captureRefund = $sale->refundCapturedPayment($refundRequest, $apiContext); // failure, error 400
try {
$sale->refund($refund, $apiContext);
//$sale->refundCapturedPayment($refund, $apiContext); // failure, error 400
} catch (Exception $ex) {
echo '<pre style="font-size:16px;">';
var_dump($ex);
echo '</pre>';
exit();
die;
}
}
アップデート2017年3月8日12:23
@私は緩く用語を使用しても、私は、一見、 'いくつかの' 進歩を遂げています。州は「完了」と戻っていますが、払い戻しは実際には起こっていません。また、サンプルのデモのように、親のお支払いIDは返されません。これに関するアイデア?私はまだこれを働かせようとしています。
これは私が現在、ペイパルから取得していた結果である:
以下object(PayPal\Api\Refund)#3 (1) {
["_propMap":"PayPal\Common\PayPalModel":private]=>
array(5) {
["id"]=>
string(17) "123456789123456789"
["create_time"]=>
string(20) "2017-03-06T20:56:32Z"
["state"]=>
string(9) "completed"
["amount"]=>
object(PayPal\Api\Amount)#9 (1) {
["_propMap":"PayPal\Common\PayPalModel":private]=>
array(3) {
["total"]=>
string(4) "0.02"
["currency"]=>
string(3) "USD"
["details"]=>
object(PayPal\Api\Details)#13 (1) {
["_propMap":"PayPal\Common\PayPalModel":private]=>
array(1) {
["subtotal"]=>
string(4) "0.02"
}
}
}
}
["links"]=>
array(1) {
[0]=>
object(PayPal\Api\Links)#17 (1) {
["_propMap":"PayPal\Common\PayPalModel":private]=>
array(3) {
["href"]=>
string(59) "https://api.paypal.com/v1/payments/refund/123456789123456789"
["rel"]=>
string(4) "self"
["method"]=>
string(3) "GET"
}
}
}
}
}
は現在、上記の応答を返すコードです...
require_once(dirname(__FILE__) . '/paypalSDK/autoload.php'); // require paypal files
require_once(dirname(__FILE__) . '/paypalSDK/paypal/rest-api-sdk-php/sample/bootstrap.php'); // require paypal files
require_once(dirname(__FILE__) . '/paypalSDK/paypal/rest-api-sdk-php/sample/common.php'); // require paypal files
// call required stuff
use PayPal\Api\Address;
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\ExecutePayment;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\PaymentCard;
use PayPal\Api\PaymentExecution;
use PayPal\Api\Transaction;
use PayPal\Api\Capture;
use PayPal\Api\Refund;
use PayPal\Api\RefundRequest;
use PayPal\Api\Sale;
$orderID = $_GET['order_id']; // internal order ID we wish to refund
// pull the details from database so we have the PayPal transction ID
$refQ = mysql_query("SELECT * FROM orders WHERE orders_ID = $orderID", $db);
$refC = mysql_num_rows($refQ);
if(!empty($refC)){
$refR = mysql_fetch_assoc($refQ);
$refNumber = $refR['orders_transaction_ref']; // PayPal transaction ID
// attempted 'PAY-' ID, results in "Requested resource ID was not found."
// $refNumber = $refR['orders_payment_ref']; // ex. PAY-123456789
$FinalTotal = $refR['orders_order_total']; // order total
// paypal credentials
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'abc',
'xyz'
)
);
$apiContext->setConfig(array('mode' => 'live',)); // live use, not sandbox
//$amount = new Amount(); // commenting these out seemingly has no effect
//$amount->setCurrency("USD") // commenting these out seemingly has no effect
// ->setTotal($FinalTotal); // commenting these out seemingly has no effect
/*
// attempted code
// ### Refund object
$refund = new Refund();
//$refund = new RefundRequest();
$refund->setAmount($FinalTotal);
*/
$refund = new Refund();
$refund->setId($refNumber);
$refund->setSaleId($refNumber);
$refund->setAmount($FinalTotal);
$refund->setReason("Testing refund code");
//$refund->get($refNumber, $apiContext);
// Attempted code, didn't work
// https://stackoverflow.com/questions/18927591/paypal-api-how-to-get-sale-id-and-refund-payment-made-via-paypal
// Fatal error: Uncaught exception 'InvalidArgumentException' with message 'paymentId cannot be null' in /home/cartridgeworkspl/public_html/cfx_controllers/paypalSDK/paypal/rest-api-sdk-php/lib/PayPal/Validation/ArgumentValidator.php:25 Stack trace: #0
// $payments = Payment::get($refNumber, $apiContext);
// $payments->getTransactions();
// $obj = $payments->toJSON();//I wanted to look into the object
// $paypal_obj = json_decode($obj);//I wanted to look into the object
// $transaction_id = $paypal_obj->transactions[0]->related_resources[0]->sale->id;
// $this->refund($transaction_id);//Call your custom refund method
try {
//var_dump($refund);
$refundResponse = Refund::get($refNumber, $apiContext);
echo '<pre>';
var_dump($refundResponse);
echo '</pre>';
echo $refundResponse->getState();
echo $refundResponse->getReasonCode();
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Get Payment", "Payment", null, null, $ex);
exit(1);
}
}
すべてのヘルプは最高にいただければ幸いです。
うん、私はそれが通貨の不足に関連している可能性があると思った。 $ refundに "setCurrency(" USD ")"を追加しようとしましたが、 "致命的なエラーが発生しました:48行目の/processRefund.node.phpの未定義メソッドPayPal \ Api \ Refund :: setCurrency() – ihateartists