Paypal API退款支付(PHP API)

时间:2015-11-25 12:38:55

标签: php paypal

这是我第一次发帖: 我希望将PayPal API集成到我的网站中,我可以成功完成付款,但不能退款部分。我在lib文件夹中看到退款api;但是,我不确定要使用哪个ID,我没有看到很多关于退款的例子。

这就是我现在所拥有的:

$refund = new Refund();
$refund->setId($payment_id);
$refund->setAmount(1000);
$refund->get($payment_id, $this->apiContext);


try {
    //$refund = Refund::get();
} 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);
}

// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

return json_decode($payment, 128);

付款明细是:

 array(10) {
      ["id"]=>
      string(28) "PAY-1WL153218P032830GKZK2BLY"
      ["intent"]=>
      string(4) "sale"
      ["state"]=>
      string(7) "created"
      ["cart"]=>
      string(17) "08X596883D298843B"
      ["payer"]=>
      array(3) {
        ["payment_method"]=>
        string(6) "paypal"
        ["status"]=>
        string(8) "VERIFIED"
        ["payer_info"]=>
        array(8) {
          ["email"]=>
          string(32) "ted.chou12-facilitator@gmail.com"
          ["first_name"]=>
          string(4) "test"
          ["last_name"]=>
          string(11) "facilitator"
          ["payer_id"]=>
          string(13) "GGYZW23EGRAY4"
          ["shipping_address"]=>
          array(7) {
            ["recipient_name"]=>
            string(16) "test facilitator"
            ["line1"]=>
            string(22) "88 Des Voeux Road West"
            ["line2"]=>
            string(6) "3F 520"
            ["city"]=>
            string(9) "Hong Kong"
            ["state"]=>
            string(9) "Hong Kong"
            ["postal_code"]=>
            string(6) "000000"
            ["country_code"]=>
            string(2) "HK"
          }
          ["phone"]=>
          string(10) "4088069385"
          ["country_code"]=>
          string(2) "US"
          ["billing_address"]=>
          array(6) {
            ["line1"]=>
            string(22) "88 Des Voeux Road West"
            ["line2"]=>
            string(6) "3F 520"
            ["city"]=>
            string(9) "Hong Kong"
            ["state"]=>
            string(9) "Hong Kong"
            ["postal_code"]=>
            string(6) "000000"
            ["country_code"]=>
            string(2) "HK"
          }
        }
      }
      ["transactions"]=>
      array(1) {
        [0]=>
        array(6) {
          ["amount"]=>
          array(3) {
            ["total"]=>
            string(7) "2340.00"
            ["currency"]=>
            string(3) "TWD"
            ["details"]=>
            array(3) {
              ["subtotal"]=>
              string(7) "2310.00"
              ["tax"]=>
              string(4) "0.00"
              ["shipping"]=>
              string(5) "30.00"
            }
          }
          ["payee"]=>
          array(1) {
            ["email"]=>
            string(35) "jaypatel512-facilitator@hotmail.com"
          }
          ["description"]=>
          string(19) "Payment description"
          ["invoice_number"]=>
          string(13) "5655a0adceedf"
          ["item_list"]=>
          array(2) {
            ["items"]=>
            array(3) {
              [0]=>
              array(5) {
                ["name"]=>
                string(2) "25"
                ["sku"]=>
                string(2) "11"
                ["price"]=>
                string(6) "529.00"
                ["currency"]=>
                string(3) "TWD"
                ["quantity"]=>
                int(3)
              }
              [1]=>
              array(5) {
                ["name"]=>
                string(13) "Warrior Model"
                ["sku"]=>
                string(2) "15"
                ["price"]=>
                string(6) "180.00"
                ["currency"]=>
                string(3) "TWD"
                ["quantity"]=>
                int(1)
              }
              [2]=>
              array(5) {
                ["name"]=>
                string(7) "dim_sum"
                ["sku"]=>
                string(2) "22"
                ["price"]=>
                string(6) "543.00"
                ["currency"]=>
                string(3) "TWD"
                ["quantity"]=>
                int(1)
              }
            }
            ["shipping_address"]=>
            array(7) {
              ["recipient_name"]=>
              string(16) "test facilitator"
              ["line1"]=>
              string(22) "88 Des Voeux Road West"
              ["line2"]=>
              string(6) "3F 520"
              ["city"]=>
              string(9) "Hong Kong"
              ["state"]=>
              string(9) "Hong Kong"
              ["postal_code"]=>
              string(6) "000000"
              ["country_code"]=>
              string(2) "HK"
            }
          }
          ["related_resources"]=>
          array(0) {
          }
        }
      }
      ["redirect_urls"]=>
      array(2) {
        ["return_url"]=>
        string(97) "..."
        ["cancel_url"]=>
        string(59) "..."
      }
      ["create_time"]=>
      string(20) "2015-11-25T11:51:10Z"
      ["update_time"]=>
      string(20) "2015-11-25T11:51:10Z"
      ["links"]=>
      array(3) {
        [0]=>
        array(3) {
          ["href"]=>
          string(79) "..."
          ["rel"]=>
          string(4) "self"
          ["method"]=>
          string(3) "GET"
        }
        [1]=>
        array(3) {
          ["href"]=>
          string(87) ".../execute"
          ["rel"]=>
          string(7) "execute"
          ["method"]=>
          string(4) "POST"
        }
        [2]=>
        array(3) {
          ["href"]=>
          string(94) "..."
          ["rel"]=>
          string(12) "approval_url"
          ["method"]=>
          string(8) "REDIRECT"
        }
      }
    }

2 个答案:

答案 0 :(得分:0)

执行付款后,您将获得sale => ID。这是你用来退款的身份。

它还会在Transactions => related_resources =>链接中包含一个完整的URI,其中包含'rel'值为'refund'的链接。

来源:https://developer.paypal.com/docs/api/#refunds

答案 1 :(得分:0)

每笔付款都会生成一个sale_id作为例子4CFG677234DFG234F。该ID将用于退款。

不要让自己与付款ID和sale_id混淆。