2014-10-13 3 views
1

우리는 paypal 서버에 신용 카드 정보를 저장합니다.Paypal pro 신용 카드 정보를 사용하여 지불

하고 응답은 같다이

stdClass 개체 ([ID] => CARD-14C32505AV6044027KQ537UQ [주] => 확인 [payer_id] => GI6WdoVY6zOq1413201872 [형태] => 비자 [수] => xxxxxxxxxxxx1111 [ 2020 [first_name] => Anu [last_name] => Jose [valid_until] => 2017-10-12T00 : 00 : 00Z [create_time] => 2014-10-13T12 : 04 : [0] => stdClass 객체 ([href] =>https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-14C32505AV6044027KQ537UQ [rel] => self [method] => GET) [update_time] => 2014-10-13T12 : 04 : 1] => stdClass 객체 ([href] =>https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-14C32505AV6044027KQ537UQ [rel] => 패치 메소드 [=] > 패치)))

이 신용 카드 ID를 사용하여 거래를 수행 할 수 있습니까? 도움이 되었습니까?

답변

1

예 확실히 위에 입력 한 신용 카드 ID를 사용하여 저장된 카드를 사용하여 지불 할 수 있습니다.

나는 당신이 사용할 수있는 컬 요청을 포함했다 :

요청을

curl -v POST "https://api.sandbox.paypal.com/v1/payments/payment" -H "Content-Type:application/json" -H "Authorization: Bearer A0430YIJHh.TrJ7DuXoVVSzzRD9BiNhc7.JUdtWFV9bm6PM" -d "{\"intent\":\"sale\",\"payer\":{\"payment_method\":\"credit_card\",\"funding_instruments\":[{\"credit_card_token\":{\"credit_card_id\":\"CARD-7F19874*H7676925VKQ55ALQ\"}}]},\"transactions\":[{\"amount\":{\"total\":\"7.47\",\"currency\":\"USD\"},\"description\":\"This is the payment transaction description.\"}]}" 

JSON 형식으로 응답

{"id":"PAY-17C52753U3213490GKQ56FJQ","create_time":"2014-10-13T14:33:10Z","updat 
e_time":"2014-10-13T14:33:28Z","state":"approved","intent":"sale","payer":{"paym 
ent_method":"credit_card","funding_instruments":[{"credit_card_token":{"credit_c 
ard_id":"CARD-7F116246H7676925VKQ55ALQ","last4":"0331","type":"visa","expire_mon 
th":"11","expire_year":"2018"}}]},"transactions":[{"amount":{"total":"7.47","cur 
rency":"USD","details":{"subtotal":"7.47"}},"description":"This is the payment t 
ransaction description.","related_resources":[{"sale":{"id":"0TD97130MF446714A", 
"create_time":"2014-10-13T14:33:10Z","update_time":"2014-10-13T14:33:28Z","amoun 
t":{"total":"7.47","currency":"USD"},"state":"completed","parent_payment":"PAY-1 
7C52753U3213490GKQ56FJQ","links":[{"href":"https://api.sandbox.paypal.com/v1/pay 
ments/sale/0TD97130MF446714A","rel":"self","method":"GET"},{"href":"https://api. 
sandbox.paypal.com/v1/payments/sale/0TD97130MF446714A/refund","rel":"refund","me 
thod":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-17 
C52753U3213490GKQ56FJQ","rel":"parent_payment","method":"GET"}]}}]}],"links":[{" 
href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-17C52753U3213490GK 
Q56FJQ","rel":"self","method":"GET"}]} 

요청 :

{ 
    "intent": "sale", 
    "payer": { 
    "payment_method": "credit_card", 
    "funding_instruments": [ 
     { 
     "credit_card_token": { 
      "credit_card_id": "CARD-7F19874*H7676925VKQ55ALQ" 
     } 
     } 
    ] 
    }, 
    "transactions": [ 
    { 
     "amount": { 
     "total": "7.47", 
     "currency": "USD" 
     }, 
     "description": "This is the payment transaction description." 
    } 
    ] 
} 

응답 :

{ 
    "id": "PAY-8U155502YW812893MKQ55D7Q", 
    "create_time": "2014-10-13T13:22:06Z", 
    "update_time": "2014-10-13T13:22:27Z", 
    "state": "approved", 
    "intent": "sale", 
    "payer": { 
    "payment_method": "credit_card", 
    "funding_instruments": [ 
     { 
     "credit_card_token": { 
      "credit_card_id": "CARD-7F19874*H7676925VKQ55ALQ", 
      "last4": "0331", 
      "type": "visa", 
      "expire_month": "11", 
      "expire_year": "2018" 
     } 
     } 
    ] 
    }, 
    "transactions": [ 
    { 
     "amount": { 
     "total": "7.47", 
     "currency": "USD", 
     "details": { 
      "subtotal": "7.47" 
     } 
     }, 
     "description": "This is the payment transaction description.", 
     "related_resources": [ 
     { 
      "sale": { 
      "id": "5U920323FW4849716", 
      "create_time": "2014-10-13T13:22:06Z", 
      "update_time": "2014-10-13T13:22:27Z", 
      "amount": { 
       "total": "7.47", 
       "currency": "USD" 
      }, 
      "state": "completed", 
      "parent_payment": "PAY-8U155502YW812893MKQ55D7Q", 
      "links": [ 
       { 
       "href": "https://api.sandbox.paypal.com/v1/payments/sale/5U920323FW4849716", 
       "rel": "self", 
       "method": "GET" 
       }, 
       { 
       "href": "https://api.sandbox.paypal.com/v1/payments/sale/5U920323FW4849716/refund", 
       "rel": "refund", 
       "method": "POST" 
       }, 
       { 
       "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-8U155502YW812893MKQ55D7Q", 
       "rel": "parent_payment", 
       "method": "GET" 
       } 
      ] 
      } 
     } 
     ] 
    } 
    ], 
    "links": [ 
    { 
     "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-8U155502YW812893MKQ55D7Q", 
     "rel": "self", 
     "method": "GET" 
    } 
    ] 
} 

당신은 아래의 PHP 코드를 사용할 수 있습니다

<?php 

//open connection 
$ch = curl_init(); 

$client="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
$secret="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 

curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token"); 
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_USERPWD, $client.":".$secret); 
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials"); 

$result = curl_exec($ch); 

if(empty($result))die("Error: No response."); 
else 
{ 
    $json = json_decode($result); 
    print_r($json->access_token); 
} 

// Now doing txn after getting the token 

$ch = curl_init(); 

$data = '{ 
    "intent": "sale", 
    "payer": { 
    "payment_method": "credit_card", 
    "funding_instruments": [ 
     { 
     "credit_card_token": { 
      "credit_card_id": "CARD-76K83451273207050KQ6MXDQ" 
     } 
     } 
    ] 
    }, 
    "transactions": [ 
    { 
     "amount": { 
     "total": "7.47", 
     "currency": "USD" 
     }, 
     "description": "This is the payment transaction description." 
    } 
    ] 
}'; 

curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment"); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer ".$json->access_token)); 

$result = curl_exec($ch); 


if(empty($result))die("Error: No response."); 
else 
{ 
    $json = json_decode($result); 
    print_r($json); 
} 

?> 
+0

안녕하세요 u는 내가 PHP 코드 내 대답을 편집 한 두 번째 요청 방법 – xyz

+0

에 대한 자세한 내용을 제공 개 pls 수 있습니다. – Eshan

+0

{ "name": "INTERNAL_SERVICE_ERROR", "message": "내부 서비스 오류가 발생했습니다", "information_link": "https://developer.paypal.com/webapps/developer/docs/"을 입력했을 때이 응답을 받았습니다. api/# INTERNAL_SERVICE_ERROR ","debug_id ":"3ddab4e897912 "} – xyz

관련 문제