{"id":272030,"date":"2016-01-13T09:07:02","date_gmt":"2016-01-13T06:07:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=272030"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=272030","title":{"rendered":"Go-\u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f PayPal API"},"content":{"rendered":"<p>       <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/ff3\/e5c\/bc1\/ff3e5cbc1ad1474a94e4d3bddd80b07e.png\"\/><\/p>\n<p>  \u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u041c\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430, \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043b\u043e\u0433\u043e\u0432, \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u043d\u0430 <a href=\"https:\/\/golang.org\/\">Go<\/a>. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c \u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u043f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043a \u043f\u043b\u0430\u0442\u0435\u0436\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 PayPal \u0438 \u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0432\u043d\u0435\u0434\u0440\u0438\u043b\u0438.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0418\u0442\u0430\u043a, \u0443 \u043c\u043d\u043e\u0433\u0438\u0445 \u0435\u0441\u0442\u044c \u043e\u043f\u044b\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 API PayPal, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c OAuth 2.0 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e: \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443-\u043a\u043b\u0438\u0435\u043d\u0442 \u0432 \u0441\u0432\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<p>  \u0414\u043b\u044f PHP, Java \u0438 Python \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 SDK \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043d\u043e \u043d\u0430\u0448 \u0441\u0435\u0440\u0432\u0438\u0441 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 GO, \u0438 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u0438\u0441\u043a SDK \u043d\u0435 \u0434\u0430\u043b \u043d\u0430\u043c \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432(<a href=\"https:\/\/github.com\/search?q=paypal+golang\">https:\/\/github.com\/search?q=paypal+golang<\/a>). \u0412 \u0438\u0442\u043e\u0433\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u043f\u044f\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 github, \u0434\u0432\u0430 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0434\u043e\u0441\u0442\u043e\u0439\u043d\u043e, \u043d\u043e \u0438\u043c\u0435\u044e\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/leebenson\/paypal\">leebenson\/paypal<\/a> (\u043d\u0435\u043f\u043e\u043b\u043d\u043e\u0435 \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435 API)<\/li>\n<li><a href=\"https:\/\/github.com\/crowdmob\/paypal\">crowdmob\/paypal<\/a> (\u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e Express Checkout)<\/li>\n<\/ul>\n<p>  \u041d\u0430\u043c \u0431\u044b\u043b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u043a\u043b\u0438\u0435\u043d\u0442 \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 <s>\u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434<\/s>.<\/p>\n<h4>OAuth 2.0<\/h4>\n<p>  \u041d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 <a href=\"https:\/\/developer.paypal.com\/\">PayPal sandbox<\/a>, \u0433\u0434\u0435 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0432\u0438\u0434\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 API.<\/p>\n<p>  \u041f\u0435\u0440\u0432\u044b\u0439 \u044d\u0442\u0430\u043f \u2014 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u043c PayPal \u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f. PayPal \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 OAuth \u0432\u0435\u0440\u0441\u0438\u0438 2.0. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0435 \u043a\u043b\u044e\u0447\u0438 (client_id \u0438 secret_key).<\/p>\n<p>  \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f client_id \u0438 secret_key \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 PayPal \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 access_token, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0414\u0430\u043b\u0435\u0435 \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432 PayPal API \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u044d\u0442\u0438\u043c \u0442\u043e\u043a\u0435\u043d\u043e\u043c \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (-u &quot;:&quot;).<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/2fd\/840\/a8c\/2fd840a8c11f429ca71649c326c833c0.png\"\/><\/p>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"go\">import &quot;github.com\/logpacker\/PayPal-Go-SDK&quot; \/\/ ... \/\/ Create a client instance c, err := paypalsdk.NewClient(&quot;clientID&quot;, &quot;secretID&quot;, paypalsdk.APIBaseSandBox) accessToken, err := c.GetAccessToken() <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u0441\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 API. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043b\u0430\u0442\u0435\u0436 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"go\">paymentResponse, err := client.CreatePayment(p) <\/code><\/pre>\n<p>  \u041c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043d\u0430\u0434 \u0442\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438 \u043e\u043f\u0438\u0441\u0430\u0442\u044c <a href=\"https:\/\/developer.paypal.com\/webapps\/developer\/docs\/api\/\">\u0432\u0441\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 API<\/a>, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439:<\/p>\n<pre><code class=\"go\">req, err := c.NewRequest(method, url, payload) c.SendWithAuth(req, &resp) <\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432 PayPal \u043c\u043e\u0436\u043d\u043e \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0444\u0430\u0439\u043b, \u043f\u043e\u043b\u043d\u044b\u0439 \u0434\u0430\u043c\u043f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u043c\u0438:<\/p>\n<pre><code class=\"go\">c.SetLogFile(&quot;\/tpm\/paypal-debug.log&quot;) <\/code><\/pre>\n<h4>\u0414\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 API<\/h4>\n<p>  \u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0439 PayPal API \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 <a href=\"https:\/\/developer.paypal.com\/webapps\/developer\/docs\/api\/\">\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/a>, \u0432\u0441\u0435 \u043e\u043d\u0438 \u0434\u0435\u043b\u044f\u0442\u0441\u044f \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u044b, Payments, Orders, Vault. \u0412 \u043a\u043b\u0438\u0435\u043d\u0442\u0435 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 API:<\/p>\n<p>  <b>POST<\/b> \/v1\/oauth2\/token \u2014 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e access_token<\/p>\n<pre><code class=\"go\">accessToken, err := c.GetAccessToken() <\/code><\/pre>\n<p>  \u0417\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0430 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439.<\/p>\n<pre><code class=\"go\">token := &quot;abcdef&quot; c.SetAccessToken(token) <\/code><\/pre>\n<p>  <b>POST<\/b> \/v1\/payments\/payment \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043b\u0430\u0442\u0435\u0436\u0430 \u0432 PayPal. \u041c\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043b\u0430\u0442\u0435\u0436\u0430.<\/p>\n<p>  \u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 PayPal \u043f\u043b\u0430\u0442\u0435\u0436:<\/p>\n<pre><code class=\"go\">amount := paypalsdk.Amount{     Total:    &quot;7.00&quot;,     Currency: &quot;USD&quot;, } redirectURI := &quot;http:\/\/example.com\/redirect-uri&quot; cancelURI := &quot;http:\/\/example.com\/cancel-uri&quot; description := &quot;Description for this payment&quot; paymentResult, err := c.CreateDirectPaypalPayment(amount, redirectURI, cancelURI, description) <\/code><\/pre>\n<p>  2. \u041f\u043b\u0430\u0442\u0435\u0436 \u043b\u044e\u0431\u043e\u0433\u043e \u0442\u0438\u043f\u0430:<\/p>\n<pre><code class=\"go\">p := paypalsdk.Payment{     Intent: &quot;sale&quot;,     Payer: &paypalsdk.Payer{         PaymentMethod: &quot;credit_card&quot;,         FundingInstruments: []paypalsdk.FundingInstrument{paypalsdk.FundingInstrument{             CreditCard: &paypalsdk.CreditCard{                 Number:      &quot;4111111111111111&quot;,                 Type:        &quot;visa&quot;,                 ExpireMonth: &quot;11&quot;,                 ExpireYear:  &quot;2020&quot;,                 CVV2:        &quot;777&quot;,                 FirstName:   &quot;John&quot;,                 LastName:    &quot;Doe&quot;,             },         }},     },     Transactions: []paypalsdk.Transaction{paypalsdk.Transaction{         Amount: &paypalsdk.Amount{             Currency: &quot;USD&quot;,             Total:    &quot;7.00&quot;,         },         Description: &quot;My Payment&quot;,     }},     RedirectURLs: &paypalsdk.RedirectURLs{         ReturnURL: &quot;http:\/\/...&quot;,         CancelURL: &quot;http:\/\/...&quot;,     }, } paymentResponse, err := client.CreatePayment(p) <\/code><\/pre>\n<p>  <b>GET<\/b> \/v1\/payments\/payment\/ID \u2014 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043b\u0430\u0442\u0435\u0436\u0435<\/p>\n<pre><code class=\"go\">payment, err := c.GetPayment(paymentID) <\/code><\/pre>\n<p>  <b>GET<\/b> \/v1\/payments\/payment \u2014 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u043f\u043b\u0430\u0442\u0435\u0436\u0435\u0439<\/p>\n<pre><code class=\"go\">payments, err := c.GetPayments() <\/code><\/pre>\n<p>  <b>GET<\/b> \/v1\/payments\/authorization\/ID \u2014 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/p>\n<pre><code class=\"go\">authID := &quot;2DC87612EK520411B&quot; auth, err := c.GetAuthorization(authID) <\/code><\/pre>\n<p>  <b>POST<\/b> \/v1\/payments\/authorization\/ID\/capture \u2014 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/p>\n<pre><code class=\"go\">capture, err := c.CaptureAuthorization(authID, &paypalsdk.Amount{Total: &quot;7.00&quot;, Currency: &quot;USD&quot;}, true) <\/code><\/pre>\n<p>  <b>POST<\/b> \/v1\/payments\/authorization\/ID\/void \u2014 \u043e\u0442\u043c\u0435\u043d\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/p>\n<pre><code class=\"go\">auth, err := c.VoidAuthorization(authID) <\/code><\/pre>\n<p>  <b>POST<\/b> \/v1\/payments\/authorization\/ID\/reauthorize \u2014 \u0440\u0435\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/p>\n<pre><code class=\"go\">auth, err := c.ReauthorizeAuthorization(authID, &paypalsdk.Amount{Total: &quot;7.00&quot;, Currency: &quot;USD&quot;}) <\/code><\/pre>\n<p>  <b>GET<\/b> \/v1\/payments\/sale\/ID \u2014 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0438<\/p>\n<pre><code class=\"go\">saleID := &quot;36C38912MN9658832&quot; sale, err := c.GetSale(saleID) <\/code><\/pre>\n<p>  <b>POST<\/b> \/v1\/payments\/sale\/ID\/refund \u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0438. \u041c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u043a \u043f\u043e\u043b\u043d\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u043f\u043b\u0430\u0442\u0435\u0436\u0430, \u0442\u0430\u043a \u0438 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0439.<\/p>\n<pre><code class=\"go\">\/\/ Full refund, err := c.RefundSale(saleID, nil) \/\/ Partial refund, err := c.RefundSale(saleID, &paypalsdk.Amount{Total: &quot;7.00&quot;, Currency: &quot;USD&quot;}) <\/code><\/pre>\n<p>  <b>GET<\/b> \/v1\/payments\/refund\/ID \u2014 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0435<\/p>\n<pre><code class=\"go\">orderID := &quot;O-4J082351X3132253H&quot; refund, err := c.GetRefund(orderID) <\/code><\/pre>\n<p>  <b>GET<\/b> \/v1\/payments\/orders\/ID \u2014 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0437\u0430\u043a\u0430\u0437\u0435<\/p>\n<pre><code class=\"go\">order, err := c.GetOrder(orderID) <\/code><\/pre>\n<p>  <b>POST<\/b> \/v1\/payments\/orders\/ID\/authorize \u2014 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u043a\u0430\u0437\u0430<\/p>\n<pre><code class=\"go\">auth, err := c.AuthorizeOrder(orderID, &paypalsdk.Amount{Total: &quot;7.00&quot;, Currency: &quot;USD&quot;}) <\/code><\/pre>\n<p>  <b>POST<\/b> \/v1\/payments\/orders\/ID\/capture \u2014 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0437\u0430\u043a\u0430\u0437\u0430 (\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e\u0439 \u0438\u043b\u0438 \u043f\u043e\u043b\u043d\u043e\u0439, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 Amount \u0438 IsFinalTransaction)<\/p>\n<pre><code class=\"go\">capture, err := c.CaptureOrder(orderID, &paypalsdk.Amount{Total: &quot;7.00&quot;, Currency: &quot;USD&quot;}, true, nil) <\/code><\/pre>\n<p>  <b>POST<\/b> \/v1\/payments\/orders\/ID\/do-void \u2014 \u043e\u0442\u043c\u0435\u043d\u0430 \u0437\u0430\u043a\u0430\u0437\u0430<\/p>\n<pre><code class=\"go\">order, err := c.VoidOrder(orderID) <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f godoc \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439 \u0434\u043b\u044f \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430: <a href=\"https:\/\/godoc.org\/github.com\/logpacker\/PayPal-Go-SDK\">https:\/\/godoc.org\/github.com\/logpacker\/PayPal-Go-SDK<\/a><\/p>\n<h4>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 CI<\/h4>\n<p>  \u0412 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0434\u0432\u0430 \u0442\u0438\u043f\u0430 \u0442\u0435\u0441\u0442\u043e\u0432: Unit \u0438 Integration. Unit \u0442\u0435\u0441\u0442\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e.<br \/>  \u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 NewClient:<\/p>\n<pre><code class=\"go\">_, err := NewClient(&quot;&quot;, &quot;&quot;, &quot;&quot;) if err == nil { \tt.Errorf(&quot;All arguments are required in NewClient()&quot;) } else { \tfmt.Println(err.Error()) } <\/code><\/pre>\n<p>  \u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043d\u0430 PayPal Sandbox, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442 \u043e\u0442\u0432\u0435\u0442\u044b \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u0438\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 go-\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b.<\/p>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043d\u0430 \u0441\u0445\u0435\u043c\u0435 \u043d\u0438\u0436\u0435:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/8c0\/caa\/35b\/8c0caa35bd144576be7015d576538f73.png\"\/><\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 CreateDirectPaypalPayment:<\/p>\n<pre><code class=\"go\">c, _ := NewClient(testClientID, testSecret, APIBaseSandBox) c.GetAccessToken()  amount := Amount{ \tTotal:    &quot;15.11&quot;, \tCurrency: &quot;USD&quot;, }  p, err := c.CreateDirectPaypalPayment(amount, &quot;http:\/\/example.com&quot;, &quot;http:\/\/example.com&quot;, &quot;test payment&quot;)  if err != nil || p.ID == &quot;&quot; { \tt.Errorf(&quot;Test paypal payment is not created&quot;) } <\/code><\/pre>\n<p>  \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0430\u043a\u043a\u0430\u0443\u043d\u0442 \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435 PayPal \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 ID \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0438\u0434\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430 \u043f\u043b\u0430\u0442\u0435\u0436\u0435 \u0441 ID PAY-5YK922393D847794YKER7MUI \u043c\u043e\u0436\u043d\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043d\u0435\u043c. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0443, \u0447\u0442\u043e \u0432\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0441 Sandbox, \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 URL API (\u0438 \u043f\u043e\u0441\u043b\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u043d\u0430 Live URL):<\/p>\n<pre><code class=\"go\">c, err := paypalsdk.NewClient(&quot;clientID&quot;, &quot;secretID&quot;, paypalsdk.APIBaseSandBox) <\/code><\/pre>\n<p>  \u0422\u0435\u0441\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u044b \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 go test, \u043d\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u0431\u044b\u0442\u044c \u0432\u0441\u0435\u0433\u0434\u0430 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c, \u0447\u0442\u043e \u043a\u043e\u0434 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Continuous Integration (CI) \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0442\u0435\u0441\u0442\u0430 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u043f\u0443\u0448\u0435 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <a href=\"https:\/\/travis-ci.org\/logpacker\/paypalsdk\">TravisCI<\/a>, \u043e\u043d \u043b\u0435\u0433\u043a\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 GitHub \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u043c, \u0432 \u043a\u043e\u0440\u043d\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043b\u0435\u0436\u0438\u0442 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f .travis.yml:<\/p>\n<pre><code class=\"go\">language: go go:  - 1.5 install:  - export PATH=$PATH:$HOME\/gopath\/bin script:  - go test -v <\/code><\/pre>\n<h4>Open Source \u0438 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0435 \u043f\u043b\u0430\u043d\u044b<\/h4>\n<p>  \u0412\u0441\u0435 \u043d\u0430\u0448\u0438 \u043d\u0430\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 GitHub, \u043e\u043d\u0438 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u044b \u043f\u043e\u0434 MIT \u043b\u0438\u0446\u043d\u0437\u0438\u0435\u0439. \u0412 \u043f\u043b\u0430\u043d\u0430\u0445 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u043a\u0443\u044e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043b\u044f Go, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0435 \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435 API (+webapps \u0438 \u0442.\u0434.)<\/p>\n<p>  \u0410\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432 GitHub.<\/p>\n<p>  \u0416\u0434\u0435\u043c \u0432\u0430\u0448\u0438\u0445 \u043a\u043e\u043c\u043c\u0438\u0442\u043e\u0432 \u0438 pull-\u0440\u0435\u043a\u0432\u0435\u0441\u0442\u043e\u0432 \u043d\u0430 <a href=\"https:\/\/github.com\/logpacker\/PayPal-Go-SDK\">logpacker\/PayPal-Go-SDK<\/a>.               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/274555\/\"> http:\/\/habrahabr.ru\/post\/274555\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/ff3\/e5c\/bc1\/ff3e5cbc1ad1474a94e4d3bddd80b07e.png\"\/><\/p>\n<p>  \u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u041c\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430, \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043b\u043e\u0433\u043e\u0432, \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u043d\u0430 <a href=\"https:\/\/golang.org\/\">Go<\/a>. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c \u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u043f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043a \u043f\u043b\u0430\u0442\u0435\u0436\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 PayPal \u0438 \u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0432\u043d\u0435\u0434\u0440\u0438\u043b\u0438.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-272030","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/272030","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=272030"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/272030\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=272030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=272030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=272030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}