{"id":3226,"date":"2020-07-10T19:28:07","date_gmt":"2020-07-10T10:28:07","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=3226"},"modified":"2025-06-19T11:04:01","modified_gmt":"2025-06-19T02:04:01","slug":"post-3226","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/3226","title":{"rendered":"PHP\u3068Stripe\u3092\u4f7f\u3063\u3066\u30b5\u30a4\u30c8\u5185\u3067\u30af\u30ec\u30b8\u30c3\u30c8\u30ab\u30fc\u30c9\u6c7a\u6e08\u51e6\u7406\u306e\u5b9f\u88c5\u65b9\u6cd5"},"content":{"rendered":"<p>PHP\u3068Stripe\u306e\u7d44\u307f\u5408\u308f\u305b\u3067Web\u30b5\u30fc\u30d3\u30b9\u306b\u30af\u30ec\u30b8\u30c3\u30c8\u30ab\u30fc\u30c9\u6c7a\u6e08\u51e6\u7406\u3092\u5c0e\u5165\u3057\u305f\u304b\u3063\u305f\u3002Stripe\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u5c0e\u5165\u304b\u3089\u5546\u54c1\u8cfc\u5165\u30da\u30fc\u30b8\uff5e\u6c7a\u6e08\u51e6\u7406\u307e\u3067\u306e\u5b9f\u88c5\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u4e0b\u6e96\u5099<\/h2>\n<h3>Stripe\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u4f5c\u6210<\/h3>\n<p>Stripe\u516c\u5f0f\u30b5\u30a4\u30c8\u3067\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u4f5c\u6210\u3057\u3066\u304a\u304f\u3002\u30c6\u30b9\u30c8\u74b0\u5883\u3092\u7528\u610f\u3059\u308b\u3060\u3051\u306a\u3089\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306e\u307f\u306e\u767b\u9332\u3067OK\u3002<\/p>\n<p><a href=\"https:\/\/stripe.com\/\" target=\"_blank\" rel=\"noopener\">https:\/\/stripe.com\/<\/a><\/p>\n<p>\u767b\u9332\u3059\u308b\u3068\u30c6\u30b9\u30c8\u7528\u306e\u300c\u516c\u958b\u53ef\u80fd\u30ad\u30fc\u300d\u300c\u30b7\u30fc\u30af\u30ec\u30c3\u30c8\u30ad\u30fc\u300d\u304c\u767a\u884c\u3055\u308c\u308b\u3002<\/p>\n<h3>\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<p>\u30b5\u30fc\u30d0\u306bSSH\u63a5\u7d9a\u3057\u9069\u5f53\u306a\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u79fb\u52d5\u5f8c\u3001\u4ee5\u4e0b\u3067\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">composer require stripe\/stripe-php\r\nphp composer.phar require stripe\/stripe-php<\/pre>\n<p>\u4ee5\u4e0b\u306fGithub\u30da\u30fc\u30b8\u306b\u30d0\u30fc\u30b8\u30e7\u30f3\u306e\u8aac\u660e\u7b49\u304c\u63b2\u8f09\u3055\u308c\u3066\u3044\u308b\u3002\u5c1a\u3001\u4eca\u56de\u691c\u8a3c\u3057\u305f\u74b0\u5883\u306fPHP5.6\u3068\u306a\u308b\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/stripe\/stripe-php\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/stripe\/stripe-php<\/a><\/p>\n<h3>\u30c6\u30b9\u30c8\u7528\u30af\u30ec\u30b8\u30c3\u30c8\u30ab\u30fc\u30c9\u60c5\u5831<\/h3>\n<p>\u4ee5\u4e0b\u30da\u30fc\u30b8\u3067\u30c6\u30b9\u30c8\u7528\u30af\u30ec\u30b8\u30c3\u30c8\u30ab\u30fc\u30c9\u60c5\u5831\u3092\u78ba\u8a8d\u3067\u304d\u308b\u3002<\/p>\n<p><a href=\"https:\/\/stripe.com\/docs\/testing\" target=\"_blank\" rel=\"noopener\">https:\/\/stripe.com\/docs\/testing<\/a><\/p>\n<p>\u30ab\u30fc\u30c9\u756a\u53f7\u306f\u8a18\u8f09\u306e\u901a\u308a\u3001CVC\u306f\u4efb\u610f\u306e3\u6587\u5b57\u3001\u30ab\u30fc\u30c9\u6709\u52b9\u671f\u9650\u306f\u672a\u6765\u5e74\u6708\u3092\u5165\u529b\u3059\u308b\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30bd\u30fc\u30b9<\/h2>\n<h3>\u8cfc\u5165\u30da\u30fc\u30b8(index.php)<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"ja\"&gt;\r\n&lt;head&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n    &lt;form action=\"charge.php\" method=\"POST\"&gt;\r\n    &lt;script src=\"https:\/\/checkout.stripe.com\/checkout.js\" class=\"stripe-button\"\r\n        data-key=\"\u516c\u958b\u53ef\u80fd\u30ad\u30fc\"\r\n        data-amount=\"10\"\r\n        data-name=\"\u30b5\u30a4\u30c8\u540d\"\r\n        data-locale=\"auto\"\r\n        data-allow-remember-me=\"false\"\r\n        data-label=\"\u8cfc\u5165\u3059\u308b\"\r\n        data-currency=\"jpy\"&gt;\r\n        \/*\r\n        data-key:\u516c\u958b\u53ef\u80fd\u30ad\u30fc\r\n        data-amount:\u30c0\u30a4\u30a2\u30ed\u30b0\u3067\u30e6\u30fc\u30b6\u306b\u8868\u793a\u3055\u308c\u308b\u91d1\u984d(JPY)\r\n        data-name:\u4f1a\u793e\u307e\u305f\u306f\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u540d\r\n        data-locale:\u8a00\u8a9e\u8a2d\u5b9a\r\n        data-allow-remember-me:\u6c7a\u6e08\u60c5\u5831\u3092\u4fdd\u5b58\u3059\u308b\u304b\u3069\u3046\u304b\u3002true\u3060\u3068\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u304c\u8868\u793a\r\n        data-label:\u30dc\u30bf\u30f3\u306b\u8868\u793a\u3055\u308c\u308b\u30c6\u30ad\u30b9\u30c8\r\n        data-currency:\u91d1\u984d\u306e\u901a\u8ca8\r\n        *\/\r\n    &lt;\/script&gt;\r\n    &lt;\/form&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<h3>\u6c7a\u6e08\u51e6\u7406\u30da\u30fc\u30b8(charge.php)<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php\r\nrequire_once('.\/vendor\/autoload.php');\r\n\\Stripe\\Stripe::setApiKey('API\u306e\u30b7\u30fc\u30af\u30ec\u30c3\u30c8\u30ad\u30fc');\r\n\r\n$chargeId = null;\r\n\r\ntry {\r\n    \/\/ (1) \u30aa\u30fc\u30bd\u30ea\uff08\u4e0e\u4fe1\u67a0\u306e\u78ba\u4fdd\uff09\r\n    $token = $_POST['stripeToken'];\r\n    $charge = \\Stripe\\Charge::create(array(\r\n        'amount' =&gt; 100,\r\n        'currency' =&gt; 'jpy',\r\n        'description' =&gt; 'test',\r\n        'source' =&gt; $token,\r\n        'capture' =&gt; false,\r\n    ));\r\n    $chargeId = $charge['id'];\r\n\r\n    \/\/ (2) \u6ce8\u6587\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u66f4\u65b0\u306a\u3069Stripe\u3068\u306f\u95a2\u4fc2\u306a\u3044\u51e6\u7406\r\n\r\n    \/\/ (3) \u58f2\u4e0a\u306e\u78ba\u5b9a\r\n    $charge-&gt;capture();\r\n\r\n    \/\/ \u8cfc\u5165\u5b8c\u4e86\u753b\u9762\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\r\n    header(\"Location: complete.php\");\r\n    exit;\r\n\r\n} catch(Exception $e) {\r\n    if ($chargeId !== null) {\r\n        \/\/ \u4f8b\u5916\u304c\u767a\u751f\u3059\u308c\u3070\u30aa\u30fc\u30bd\u30ea\u3092\u53d6\u308a\u6d88\u3059\r\n        \\Stripe\\Refund::create(array(\r\n            'charge' =&gt; $chargeId,\r\n        ));\r\n    }\r\n\r\n    \/\/ \u30a8\u30e9\u30fc\u753b\u9762\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\r\n    header(\"Location: error.php\");\r\n    exit;\r\n}\r\n?&gt;<\/pre>\n<p>\u6c7a\u6e08\u5b8c\u4e86\u30da\u30fc\u30b8\u3068\u30a8\u30e9\u30fc\u30da\u30fc\u30b8\u306f\u9069\u5f53\u306bHTML\u3067\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u66f8\u3051\u3070\u826f\u3044\u3002\u307e\u305f\u8cfc\u5165\u30da\u30fc\u30b8\u306b\u8a2d\u7f6e\u3059\u308bJavaScript\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u306f\u4ee5\u4e0b\u30da\u30fc\u30b8\u3067\u8a73\u7d30\u3092\u78ba\u8a8d\u3067\u304d\u308b\u3002<\/p>\n<p><a href=\"https:\/\/stripe.com\/docs\/legacy-checkout\" target=\"_blank\" rel=\"noopener\">https:\/\/stripe.com\/docs\/legacy-checkout<\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>\u305d\u306e\u4ed6<\/h2>\n<h3>\u6c7a\u6e08\u540d<\/h3>\n<p>\u4eca\u56de\u306f\u30c6\u30b9\u30c8\u7528\u30af\u30ec\u30ab\u3067\u691c\u8a3c\u3057\u305f\u70ba\u78ba\u8a8d\u306e\u3057\u3088\u3046\u304c\u306a\u3044\u304c\u3001\u672c\u756a\u7528\u30af\u30ec\u30ab\u3067\u6c7a\u6e08\u3057\u305f\u969b\u306b\u660e\u7d30\u306b\u8868\u793a\u3055\u308c\u308b\u6c7a\u6e08\u540d\u304c\u3069\u3046\u306a\u308b\u306e\u304b\u6c17\u306b\u306a\u3063\u305f\u3002<\/p>\n<p>\u8abf\u3079\u3066\u307f\u308b\u3068\u30ab\u30fc\u30c9\u4f1a\u793e\u306b\u3088\u3063\u3066\u7570\u306a\u308a\u300c\u30aa\u30f3\u30e9\u30a4\u30f3\u6c7a\u6e08\u300d\u307e\u305f\u306f\u300cST* \u767b\u9332\u3057\u305f\u30b5\u30fc\u30d3\u30b9\u540d\u300d\u306e\u3069\u3061\u3089\u304b\u3067\u8868\u793a\u3055\u308c\u308b\u6a21\u69d8\u3002<\/p>\n<h3>\u5373\u6642\u6c7a\u6e08\u3057\u306a\u3044\u5834\u5408<\/h3>\n<p>\u4f8b\u3048\u3070\u3060\u3051\u3069\u300c\u5165\u8377\u5f85\u3061\u306e\u5546\u54c1\u3067\u8cfc\u5165\u624b\u7d9a\u304d\u5f8c\u3001\u5546\u54c1\u304c\u5165\u8377\u3055\u308c\u3066\u304b\u3089\u767a\u9001\u300d\u307f\u305f\u3044\u306a\u30b1\u30fc\u30b9\u3067\u5373\u6642\u306b\u6c7a\u6e08\u306f\u3057\u306a\u3044\u65b9\u304c\u3044\u3044\u5834\u5408\u306f\u58f2\u308a\u4e0a\u3052\u306e\u78ba\u5b9a\u306f\u305b\u305a\u306b\u3001\u5546\u54c1\u767a\u9001\u7b49\u3092\u884c\u3063\u3066\u304b\u3089Stripe\u306e\u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u3088\u308a\u78ba\u5b9a\u51e6\u7406\u3092\u884c\u3046\u5f62\u306b\u306a\u308b\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3\u6c7a\u6e08\u3057\u305f\u3044\u5834\u5408(2021\/03\/19\u8ffd\u8a18)<\/h2>\n<p>\u300c<a href=\"https:\/\/taitan916.info\/blog\/archives\/3232\" target=\"_blank\" rel=\"noopener\">PHP\u3068Stripe\u3067\u5b9a\u984d\u8ab2\u91d1(\u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3)\u5b9f\u88c5\u3059\u308b\u65b9\u6cd5<\/a>\u300d\u3092\u30e1\u30e2\u3057\u305f\u306e\u3067\u8ffd\u8a18\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u6240\u611f<\/h2>\n<p>\u30af\u30ec\u30ab\u6c7a\u6e08\u30b7\u30b9\u30c6\u30e0\u3092\u5c0e\u5165\u3057\u305f\u3053\u3068\u304c\u306a\u304f\u3001\u5b9f\u88c5\u306b\u3042\u305f\u308a\u300c\u5de5\u6570\u304c\u304b\u304b\u308a\u305d\u3046\u300d\u300c\u96e3\u3057\u305d\u3046\u300d\u7b49\u3005\u306e\u5370\u8c61\u3092\u6301\u3063\u3066\u3044\u305f\u304cStripe\u3060\u3068\u975e\u5e38\u306b\u7c21\u5358\u306b\u5c0e\u5165\u3067\u304d\u305f\u3002<\/p>\n<p>\u3042\u3068\u306f\u6708\u984d(\u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3)\u6c7a\u6e08\u306b\u3064\u3044\u3066\u3082\u8a66\u3057\u3066\u304a\u304d\u305f\u3044\u3068\u3053\u308d\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u53c2\u8003\u30b5\u30a4\u30c8<\/h2>\n<p><a href=\"https:\/\/qiita.com\/p_s_m_t\/items\/a69dfbc75804fe86ad9c\" target=\"_blank\" rel=\"noopener\">https:\/\/qiita.com\/p_s_m_t\/items\/a69dfbc75804fe86ad9c<\/a><\/p>\n<p><a href=\"https:\/\/techracho.bpsinc.jp\/baba\/2018_05_28\/56914\" target=\"_blank\" rel=\"noopener\">https:\/\/techracho.bpsinc.jp\/baba\/2018_05_28\/56914<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u3068Stripe\u306e\u7d44\u307f\u5408\u308f\u305b\u3067Web\u30b5\u30fc\u30d3\u30b9\u306b\u30af\u30ec\u30b8\u30c3\u30c8\u30ab\u30fc\u30c9\u6c7a\u6e08\u51e6\u7406\u3092\u5c0e\u5165 ... <\/p>\n","protected":false},"author":1,"featured_media":6947,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[110,111],"class_list":["post-3226","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-stripe","tag-checkout"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/3226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=3226"}],"version-history":[{"count":1,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/3226\/revisions"}],"predecessor-version":[{"id":6949,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/3226\/revisions\/6949"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/6947"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=3226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=3226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=3226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}