PayPal APIã®ä½¿ãæ¹ ãã®4 ã å®ææ¯æãã®å®è£
ãPayPalの使い方 その2 - Express Checkout APIによる課金システムの実装 解説ãã§ä½æããExpress Checkoutã®å®è£ ãå¤æ´ãã¦å®ææ¯æãã試ãã¦ã¿ãã®ã§ã¾ã¨ãã¦ã¿ã¾ããã
å®ææ¯æãã®æ¦è¦ã¾ã¨ã
å®ææ¯æãã®æ¦è¦ã«ã¤ãã¦ã¯gihyoã®ãµã¤ãã®PayPalã®é£è¼è¨äºãåèã«ãªãã¾ãã
ãPayPal APIå°å
¥ã»æ´»ç¨ã¬ã¤ã - 第3åãå®ææ¯æããå®ç¾ãããªã«ã¼ãªã³ã°ãã¤ã¡ã³ãã®å®è£
ã
http://gihyo.jp/dev/serial/01/paypal_api/0003
ã¾ããå®ææ¯æãã¯Express Checkout APIã使ããªãã¦ããSubscribeãã¿ã³ã§ãå®ç¾å¯è½ã§ãã
https://www.paypal.com/cgi-bin/webscr?cmd=_pdn_subscr_techview_outside
å®ææ¯æãã®PayPalã®å ¬å¼ããã¥ã¡ã³ãã¯ãã¡ã
è±èªï¼https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECRecurringPayments
æ¥æ¬èª:https://cms.paypal.com/jp/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_WPRecurringPayments
å®ææ¯æãã®æµã
以ä¸ã®å³ã¯ãå®ææ¯æãã®æµãã説æããå³ã§ã(PayPalã®ããã¥ã¡ã³ãããå¼ç¨)ã
å®ææ¯æãã®å®è£
ã¯ãExpress Checkout APIã®å¼ã³åºãã«å ãã¦å®ææ¯æãã®å種è¨å®ãä¿åããRecurring Payment Profile(å®ææ¯æãå人è¨å®)ãä½æãã¾ãã
å³ã®ä¸ã§ã主ãªå¦çã¯ä»¥ä¸ã®ããã«ãªãã¾ãã
- (1) L_BILLINGTYPE0=RecurringPaymentsããããã£ãæå®ãã¦SetExpressCheckoutãå¼ã¶
- (3) Tokenãæå®ãã¦RePayPalã«ãªãã¤ã¬ã¯ã
- (4) GetExpressCheckoutDetailsãå¼ã³åºãã¦å®ææ¯æããããã£ã¼ã«ã«æå®ããæ å ±ãåå¾
- (6) å ¥ä¼éãªã©ã¯ã³ã¿ã¤ã ãã¤ã¡ã³ããå¿ è¦ãªå ´åã®ã¿DoExpressCheckoutPaymentã§èª²é
- (7) CreateRecurringPaymentsProfileãå¼ã³åºãã¦å®ææ¯æããããã£ã¼ã«ãä½æ
ä»åã説æç¨ã®ãµã³ãã«ãGithubã«ã¢ãããã¾ããã®ã§åèã«ãã¦ãã ããã
https://github.com/hrendoh/PayPal-Recurring-Payment-example
ã¢ããªã±ã¼ã·ã§ã³ã¯ãåã®ããã°ã§ç´¹ä»ããExpress Checkoutã®ãµã³ãã«ãåºã«å®ææ¯æãã®å¦çã追å ãã¦ãã¾ãã
以ä¸ãExpress Checkoutã§å®ææ¯æããéå§ããéã«å¿ è¦ãªæé ã®è©³ç´°ã解説ãã¾ãã
(1) L_BILLINGTYPE0=RecurringPaymentsããããã£ãæå®ãã¦SetExpressCheckoutãå¼ã¶
å®ææ¯æããSetExpressCheckoutã§ãã©ã³ã¶ã¯ã·ã§ã³ãéå§ãã¾ãã
æèµ·ãæãã®éã«æå®ããå¿
è¦ã®ãããã©ã¡ã¼ã¿ã¯ä»¥ä¸ã®éãã§ãã
- BILLINGTYPE
ãRecurringPaymentsããæå®ãã¾ãã
- BILLINGAGREEMENTDESCRIPTION
BILLINGTYPEãã¨ã«èª¬æãæå®ãã¾ããè¤æ°æå®ããå ´åã¯ãL_BILLINGTYPE0ã«å¯¾ãã¦L_BILLINGAGREEMENETDESCRIPTION0ãL_BILLINGTYPE1ã«å¯¾ãã¦L_BILLINGAGREEMENETDESCRIPTION1ã¨ããããã«0-9ã¾ã§æå®ã§ãã¾ã*1ã
- ãIf there is no associated purchaseãã¯ã³ã¿ã¤ã ãã¤ã¡ã³ããåæã«å©ç¨ããªãå ´åã¯ãAMT=0ãæå®ã¨ããã¥ã¡ã³ãã«ã¯æ¸ãã¦ããã¾ããã¡ãªã¿ã«AMTãæå®ããªãã¦ãéãã¾ããã
ã¡ãªã¿ã«ããã©ã¡ã¼ã¿è¶³ããªãå ´åã以ä¸ã®æ§ãªã¨ã©ã¼ãè¿ããã¾ããããBILLINGAGREEMENTDESCRIPTIONãã追å ãå¿ãã
SetExpressCheckout API call failed. Detailed Error Message: Recurring payments profile description must be provided if the billing agreement type is recurring payments.Short Error Message: Invalid DataError Code: 10478Error Severity Code: Error
æ£ãããã©ã¡ã¼ã¿ã渡ãã¨ã以ä¸ã®ãããªå¥ç´ã«åæãããã¼ã¸ã表示ããã¾ã*2ã
ãBILLINGAGREEMENTDESCRIPTIONãã«æå®ããå¤ã[注ææ¦è¦]ã®[説æ]ã«è¡¨ç¤ºããã¦ãã¾ãã
ã¾ããå®ææ¯æç¨ã«[åæãã¦ç¶è¡]ã«ãã¿ã³ã®ã©ãã«ãå¤ãã£ã¦ãã¾ã*3ã
GetExpressCheckoutDetailsãå¼ã³åºãã¦å®ææ¯æããããã£ã¼ã«ã«æå®ããæ å ±ãåå¾
ã¯ã³ã¿ã¤ã ãã¤ã¡ã³ããå«ã¾ãªãå ´åãã次ã®CreateRecurringPaymentsProfileã«æå®ãããã©ã¡ã¼ã¿ãGetExpressCheckoutDetailsãå¼ã³åºãã¦åå¾ããå¿ è¦ãããã¾ãã
CreateRecurringPaymentsProfileãå¼ã³åºãã¦å®ææ¯æããããã£ã¼ã«ãä½æ
CreateRecurringPaymentsProfileã®å®è¡ã¯ãPayPalã§æ¯æãã®å ´åã¨ã¯ã¬ã¸ããã«ã¼ãã§ãã¤ã¬ã¯ã決æ¸ããå ´åã§æå®ãããã©ã¡ã¼ã¿ãç°ãªãã®ã§æ³¨æãå¿
è¦ã§ãã
ã¾ããããã¤ãã®ãã©ã¡ã¼ã¿ã¯GetExpressCheckoutDetailsã§åå¾ããå¤ãæå®ããå¿
è¦ãããã¾ãã
å¿ é ãã©ã¡ã¼ã¿
- PROFILESTARTDATE
å®ææ¯æãã®è«æ±éå§æ¥ã
- DESC
SetExpressCheckoutã«æå®ããBILLINGAGREEMENTDESCRIPTIONãã©ã¡ã¼ã¿ã¨åãå¤ãæå®ãã¾ãã
åãå¤ãããªãã¨ã¨ã©ã¼ã«ãªãã®ã§æ³¨æã
- AMT
å課éã®éé¡
- CURRENCYCODE
é貨
- BILLINGPERIOD:課éã¹ã±ã¸ã¥ã¼ã«ã®å¨æãæå®ãã¾ãã
- Day
- Week
- SemiMonth
- Month
- Year
- BILLINGFREQUENCY
ããã¥ã¡ã³ãã®èª¬æãåããã«ããã
BILLINGPERIODå
ã®è«æ±é »åº¦ãBILLINGPERIOD=Monthã®ã¨ãã«BILLINGFREQUENCY=5ã«ããã¨1ã¶æã«5åè«æ±ãããï¼
以ä¸ã¯ãæ¯ææ¹æ³ã«ãã£ã¦ç°ãªãå¿ é ãã©ã¡ã¼ã¿
- TOKEN:PayPalæ¯æãã®å ´åãExpress Checkoutã®TOKENãæå®ãã¾ããã¾ããTOKENãæå®ããå ´åã¯ä»¥ä¸ã®ãã©ã¡ã¼ã¿ãå¿
é ã«ãªãã¾ãã
- SHIPTONAME
- SHIPTOSTREET
- SHIPTOCITY
- SHIPTOSTATE
- SHIPTOZIP
- SHIPTOCOUNTRY
- CreditCard:ã¯ã¬ã¸ããã«ã¼ãã«ãããã¤ã¬ã¯ã決æ¸ãå©ç¨ããå ´åããã®ã¨ãTOKENã¯çç¥ããã
- CREDITCARDTYPE
- ACCT
- EXPDATE
- CVV2
ãã¤ã¬ã¯ã決æ¸ã®ä¾ã¯å®éã«ã¯è©¦ãã¦ãã¾ããã®ã§ã以ä¸ã®èª¬æãªã©ãåèã«ãã¦ã¿ã¦ãã ããã
https://www.x.com/blogs/magarvin/2009/12/21/sample-createrecurringpaymentsprofile--direct-payment
ä½æããPayPal決æ¸ã®ãµã³ãã«ãå®è¡ãã¦POSTãããã©ã¡ã¼ã¿ã¯ãã®ããã«ãªãã¾ãã
METHOD=CreateRecurringPaymentsProfile&VERSION=64&PWD=1308542256&USER=Seller_1308542242_biz_api1.gmail.com&SIGNATURE=A4U73r.r18rhxStXoULiMg6K9OGOAuMapjAYMHD5UPtAMTjgTgK5VKnK&TOKEN=EC-99H66270JP9985642&SHIPTONAME=Test+User&SHIPTOSTREET=Nishi+4-chome%2C+Kita+55-jo%2C+Kita-ku&SHIPTOCITY=Shibuya-ku&SHIPTOSTATE=Tokyo&SHIPTOZIP=150-0002&SHIPTOCOUNTRY=JP&PROFILESTARTDATE=2011-07-01T0%3A0%3A0&DESC=Test+Recurring+Payment%28%241+monthly%29&BILLINGPERIOD=Month&BILLINGFREQUENCY=5&AMT=1&CURRENCYCODE=USD&IPADDRESS=::1&BUTTONSOURCE=PP-ECWizard
CreateRecurringPaymentsProfileã¡ã½ããã¯å¿çã«ãPROFILEIDããè¿ãã¾ããå®ææ¯æããããã£ã¼ã«ã®æ å ±ãå¾ããåç §ããéã«å¿ è¦ã¨ãªãã®ã§å¤ã¯ã¢ããªã±ã¼ã·ã§ã³å´ã§ä¿æãã¦ããå¿ è¦ãããã¾ãã
ãã¤ã¢ã«ã¦ã³ããã¼ã¸ã§å®ææ¯æãã確èª
å®ææ¯æããå¥ç´ããã¨ããã®æ
å ±ã¯è³¼å
¥è
ã®ãã¤ã¢ã«ã¦ã³ãã®æ¦è¦ã§ç¢ºèªãããã¨ãã§ãã¾ãã
詳細ãéãã¨ãããªæã
ãããã£ã¼ã«æ å ±ã®åç §
å®éã«ãµã¼ãã¹ãæä¾ããéã«ã¯ãå®ææ¯æããããã£ã¼ã«ã®ã¹ãã¼ã¿ã¹ãæå¹ãã©ãããå®æçã«ãã§ãã¯ããå¿
è¦ãããã¾ãã
æå¾ã«ãå®ææ¯æããããã£ã¼ã«ã¹ãã¼ã¿ã¹ã確èªããã¡ã½ããã«ã¤ãã¦ç°¡åã«ã¾ã¨ãã¦ããã¾ãã
GetRecurringPaymentsProfileDetails
å®ææããããã£ã¼ã«æ å ±ãåå¾ãã¾ããCreateRecurringPaymentsProfileãå®è¡ãã¦åå¾ãããPROFILEIDãããã©ã¡ã¼ã¿ã«æå®ãã¾ãã
ManageRecurringPaymentsProfileStatus
å®ææãã®ãã£ã³ã»ã«ãä¸æåæ¢ãåéãå®è¡ãã¾ãã
CreateRecurringPaymentsProfileãå®è¡ãã¦åå¾ãããPROFILEIDãã¨ä»¥ä¸ã®ãACTIONããå¿
é ãã©ã¡ã¼ã¿ã§ãã
- Cancel: æå¹ã¾ãã¯ä¸æåæ¢ç¶æ ã®è¨å®ã®ã¿ããã£ã³ã»ã«
- Suspend: æå¹ç¶æ ã®è¨å®ã®ã¿ãä¸æåæ¢
- Reactivate: ä¸æåæ¢ç¶æ ã®è¨å®ã®ã¿ãå©ç¨åé
UpdateRecurringPaymentsProfile
å®ææããããã£ã¼ã«æ å ±ãæ´æ°ãã¾ããæªæãã®å¯¾å¿ã¯ãã®ã¡ã½ããã§è¡ãã¾ãã
*1:1ã¤ã®å ´åã¯ãL_ãã¨ãnãã¯ä¸è¦ã§ããL_ã¯ãªã¹ãã®ç¥ï¼
*2:ããã¯Sandboxã®ãã¼ã¸ãªã®ã§å®éã®ãã¼ã¸ã¨ã¯ç°ãªãããããã¾ãã
*3:ãªãã¡ã¬ã³ã¹ãã©ã³ã¶ã¯ã·ã§ã³ã®æã¨åã