2013-05-14 8 views
0

Paypal 샌드 박스를 사용하여 grails 프로젝트에서 통합 테스트를 통해 Paypal 지급을 테스트하려고합니다. 이 단계에서 REST API를 사용하여 Paypal 지불을 생성하려고합니다.Paypal REST API 불량 요청

코드 :

def jsonPaypalPayment =''' 
{ 
    "intent": "sale", 
    "redirect_urls": [{ 
    "return_url": "http://<return URL here>", 
    "cancel_url": "http://<cancel URL here>" 
    }], 
    "payer": { 
    "payment_method": "paypal" 
    }, 
    "transactions": [{ 
    "amount": { 
     "total": "0.10", 
     "currency": "USD", 
    }, 
    "description": "This is the payment transaction description." 
    }] 
} 
''' 

def client = new RESTClient("https://api.sandbox.paypal.com") 
client.contentType = ContentType.JSON 
client.headers.'Authorization' = "${tokenType} ${accessToken}" 
def resp = client.post(path: "/v1/payments/payment", body: jsonPaypalPayment) 

tokentype 매와 accessToken은 이전 단계에서 성공적으로 검색됩니다.

post 메서드는 "400 Bad Request"응답을 반환합니다. 아주 사소한 수정 작업을 가진 문서에서 샘플 요청을 받았습니다.

전체 디버그 출력 : 나는 REST API는 베타 인 것으로 나타났습니다

2013-05-14 12:31:08,276 <> [main] DEBUG impl.conn.SingleClientConnManager - Get connection for route HttpRoute[{s}->https://api.sandbox.paypal.com] 
2013-05-14 12:31:08,461 <> [main] DEBUG client.protocol.RequestAddCookies - CookieSpec selected: best-match 
2013-05-14 12:31:08,461 <> [main] DEBUG impl.client.DefaultHttpClient - Attempt 1 to execute request 
2013-05-14 12:31:08,461 <> [main] DEBUG impl.conn.DefaultClientConnection - Sending request: POST /v1/payments/payment HTTP/1.1 
2013-05-14 12:31:08,461 <> [main] DEBUG apache.http.wire - >> "POST /v1/payments/payment HTTP/1.1[EOL]" 
2013-05-14 12:31:08,461 <> [main] DEBUG apache.http.wire - >> "Accept: application/json, application/javascript, text/javascript[EOL]" 
2013-05-14 12:31:08,464 <> [main] DEBUG apache.http.wire - >> "Authorization: Bearer 6-OVyjZ1VqEPctkqa7k72DIkwqY0kL2dIfIy6dSkdOc[EOL]" 
2013-05-14 12:31:08,464 <> [main] DEBUG apache.http.wire - >> "Content-Length: 356[EOL]" 
2013-05-14 12:31:08,464 <> [main] DEBUG apache.http.wire - >> "Content-Type: application/json[EOL]" 
2013-05-14 12:31:08,464 <> [main] DEBUG apache.http.wire - >> "Host: api.sandbox.paypal.com[EOL]" 
2013-05-14 12:31:08,464 <> [main] DEBUG apache.http.wire - >> "Connection: Keep-Alive[EOL]" 
2013-05-14 12:31:08,464 <> [main] DEBUG apache.http.wire - >> "Accept-Encoding: gzip,deflate[EOL]" 
2013-05-14 12:31:08,464 <> [main] DEBUG apache.http.wire - >> "[EOL]" 
2013-05-14 12:31:08,464 <> [main] DEBUG apache.http.headers - >> POST /v1/payments/payment HTTP/1.1 
2013-05-14 12:31:08,464 <> [main] DEBUG apache.http.headers - >> Accept: application/json, application/javascript, text/javascript 
2013-05-14 12:31:08,464 <> [main] DEBUG apache.http.headers - >> Authorization: Bearer 6-OVyjZ1VqEPctkqa7k72DIkwqY0kL2dIfIy6dSkdOc 
2013-05-14 12:31:08,465 <> [main] DEBUG apache.http.headers - >> Content-Length: 356 
2013-05-14 12:31:08,465 <> [main] DEBUG apache.http.headers - >> Content-Type: application/json 
2013-05-14 12:31:08,465 <> [main] DEBUG apache.http.headers - >> Host: api.sandbox.paypal.com 
2013-05-14 12:31:08,465 <> [main] DEBUG apache.http.headers - >> Connection: Keep-Alive 
2013-05-14 12:31:08,465 <> [main] DEBUG apache.http.headers - >> Accept-Encoding: gzip,deflate 
2013-05-14 12:31:08,466 <> [main] DEBUG apache.http.wire - >> "[\n]" 
2013-05-14 12:31:08,466 <> [main] DEBUG apache.http.wire - >> "{[\n]" 
2013-05-14 12:31:08,466 <> [main] DEBUG apache.http.wire - >> " "intent": "sale",[\n]" 
2013-05-14 12:31:08,466 <> [main] DEBUG apache.http.wire - >> " "redirect_urls": [{[\n]" 
2013-05-14 12:31:08,466 <> [main] DEBUG apache.http.wire - >> " "return_url": "http://<return URL here>",[\n]" 
2013-05-14 12:31:08,466 <> [main] DEBUG apache.http.wire - >> " "cancel_url": "http://<cancel URL here>"[\n]" 
2013-05-14 12:31:08,471 <> [main] DEBUG apache.http.wire - >> " }],[\n]" 
2013-05-14 12:31:08,471 <> [main] DEBUG apache.http.wire - >> " "payer": {[\n]" 
2013-05-14 12:31:08,471 <> [main] DEBUG apache.http.wire - >> " "payment_method": "paypal"[\n]" 
2013-05-14 12:31:08,471 <> [main] DEBUG apache.http.wire - >> " },[\n]" 
2013-05-14 12:31:08,471 <> [main] DEBUG apache.http.wire - >> " "transactions": [{[\n]" 
2013-05-14 12:31:08,471 <> [main] DEBUG apache.http.wire - >> " "amount": {[\n]" 
2013-05-14 12:31:08,471 <> [main] DEBUG apache.http.wire - >> "  "total": "0.10",[\n]" 
2013-05-14 12:31:08,471 <> [main] DEBUG apache.http.wire - >> "  "currency": "USD",[\n]" 
2013-05-14 12:31:08,471 <> [main] DEBUG apache.http.wire - >> " },[\n]" 
2013-05-14 12:31:08,471 <> [main] DEBUG apache.http.wire - >> " "description": "This is the payment transaction description."[\n]" 
2013-05-14 12:31:08,471 <> [main] DEBUG apache.http.wire - >> " }][\n]" 
2013-05-14 12:31:08,471 <> [main] DEBUG apache.http.wire - >> "}[\n]" 
2013-05-14 12:31:08,661 <> [main] DEBUG apache.http.wire - << "HTTP/1.1 400 Bad Request[EOL]" 
2013-05-14 12:31:08,662 <> [main] DEBUG apache.http.wire - << "Server: Apache-Coyote/1.1[EOL]" 
2013-05-14 12:31:08,662 <> [main] DEBUG apache.http.wire - << "Date: Tue, 14 May 2013 16:31:08 GMT[EOL]" 
2013-05-14 12:31:08,662 <> [main] DEBUG apache.http.wire - << "Connection: close[EOL]" 
2013-05-14 12:31:08,662 <> [main] DEBUG apache.http.wire - << "PayPal-Debug-Id: 381936211a402[EOL]" 
2013-05-14 12:31:08,662 <> [main] DEBUG apache.http.wire - << "Content-Type: application/json[EOL]" 
2013-05-14 12:31:08,662 <> [main] DEBUG apache.http.wire - << "Content-Length: 195[EOL]" 
2013-05-14 12:31:08,662 <> [main] DEBUG apache.http.wire - << "Connection: close[EOL]" 
2013-05-14 12:31:08,662 <> [main] DEBUG apache.http.wire - << "[EOL]" 
2013-05-14 12:31:08,662 <> [main] DEBUG impl.conn.DefaultClientConnection - Receiving response: HTTP/1.1 400 Bad Request 
2013-05-14 12:31:08,662 <> [main] DEBUG apache.http.headers - << HTTP/1.1 400 Bad Request 
2013-05-14 12:31:08,662 <> [main] DEBUG apache.http.headers - << Server: Apache-Coyote/1.1 
2013-05-14 12:31:08,662 <> [main] DEBUG apache.http.headers - << Date: Tue, 14 May 2013 16:31:08 GMT 
2013-05-14 12:31:08,662 <> [main] DEBUG apache.http.headers - << Connection: close 
2013-05-14 12:31:08,662 <> [main] DEBUG apache.http.headers - << PayPal-Debug-Id: 381936211a402 
2013-05-14 12:31:08,662 <> [main] DEBUG apache.http.headers - << Content-Type: application/json 
2013-05-14 12:31:08,662 <> [main] DEBUG apache.http.headers - << Content-Length: 195 
2013-05-14 12:31:08,662 <> [main] DEBUG apache.http.headers - << Connection: close 
2013-05-14 12:31:08,664 <> [main] DEBUG apache.http.wire - << "{"name":"MALFORMED_REQUEST","message":"Incoming JSON request does not map to API request","information_link":"https://developer.paypal.com/docs/api/#MALFORMED_REQUEST","debug_id":"381936211a402"}" 
2013-05-14 12:31:08,664 <> [main] DEBUG impl.conn.SingleClientConnManager - Releasing connection [email protected]668b2 
2013-05-14 12:31:08,664 <> [main] DEBUG impl.conn.SingleClientConnManager - Released connection open but not reusable. 
2013-05-14 12:31:08,664 <> [main] DEBUG impl.conn.DefaultClientConnection - Connection shut down 
| Failure: testPayPalPayment(merch.storeapi.OrderIntegrationTests) 
| groovyx.net.http.HttpResponseException: Bad Request 

. 문서가 정확합니까? 엔드 포인트 테스트를 마쳤습니까? REST API는 언제 릴리스 예정입니까? 나쁜 요청에 관한 통찰력? 미리 감사드립니다.

답변

4

currency 값 다음에 쉼표가 추가 된 것으로 보이는 JSON은 유효하지 않습니다. 당신의 응답을

{ 
    "intent":"sale", 
    "redirect_urls":{ 
     "return_url":"http://<return URL here>", 
     "cancel_url":"http://<cancel URL here>" 
    }, 
    "payer":{ 
     "payment_method":"paypal" 
    }, 
    "transactions":[ 
     { 
     "amount":{ 
      "total":"7.47", 
      "currency":"USD" 
     }, 
     "description":"This is the payment transaction description." 
     } 
    ] 
} 

Source

+0

감사 :

다음은 문서에서 바로 올바른 예이다. 나는 실제로 여분의 쉼표를 잡았고 시험을 다시했다. 같은 결과. – emiles

+1

그러나 json 문자열을 복사했습니다. 'redirect_urls'가 배열이 아닙니다. 또한 URL은 실제 URL이어야합니다. 이 변경 후에 작동했습니다. 응답 해 주셔서 다시 한 번 감사드립니다. – emiles