首页
开发手册
应用中心
工具
用户中心
Use the Square Platform for Credit Card Payments
English
中文简体
English
上一篇
下一篇
#FoundPHP Square use ### PHP Square Introduction Square is a foreign credit card platform. Most foreign payment methods are credit card payments. The platform is suitable for projects where users are foreign users. It also provides a separate financial management panel that can be accessed by entering the Square panel for management. `Square credit card payment is not recommended for domestic projects` ----------- #### Configuration parameter ##### The id and key provided by the demo are the parameters of the test environment. Please modify the configuration of the id and key when you use it officially (the id and key of the formal environment and the test environment are different) ```php //Configure payment platform $config['pay']['dev'] = 1;//1 Open the test environment 0 formal environment $config['pay']['type'] ='square'; $config['pay']['id'] ='sandbox-sq0idb-dCpasBwaHdKXoZjsw3VCvA'; $config['pay']['location'] ='Q9A1FNHYD7M50'; $config['pay']['key'] ='EAAAEPl9Yac8HzDvq6o-sQ0TLPkWDcpFfkVnNRoUKbOMS15K8vm1NYdshbeZ-O_T'; $config['pay']['log_file'] = $RAND_DIR."pay_logs/".dates(time(),"Y-m-d").".txt";//Log file ``` #### Instantiate Payment Plugin ```php //Instantiate the class $FoundPHP_pay = load('class/pay/pay','FoundPHP_pay',$config['pay']); ``` ![](https://dev.foundphp.com/data/file/edit/20/04/30/200430_16376957.png) #### 2.Add Customer ```php //Customer Information $data_ary = array( 'id' => 1, 'first_name' => 'vicky', 'last_name' => 'Zhu', 'email' => '2335097467@qq.com', ); //Create customers $result = $FoundPHP_pay->create_customer($data_ary); print_R($result); ``` ##### Output Result ```php array( 'code' => 1, 'Use' => Create Customer, 'data' => TYJB05H9Y8T4Z04V976BNDSGDC,//The customer id returned by square must be saved. ); ``` #### 3. Add Credit Card Use Square's own payment form to bind a credit card ![](https://dev.foundphp.com/data/file/edit/20/08/12/200812_10268763.png) ###### Test credit card parameters |Number|CVV|Verification Code| | ------------ | ------------ | ----------| |4111 1111 1111 1111|111|x| |4310 0000 0020 1019|111|123456| |5105 1051 0510 5100|111|x| |5500 0000 0020 1016|111|123456| |6011 0000 0000 0004|111|x| |6011 0000 0020 1016|111|123456| |3000 0000 0000 04|111|x| |3569 9900 1009 5841|111|x| |3400 000000 00009|1111|x| |3700 000002 01014|1111|123456| |6222 9888 1234 0000|123|x| ##### Pull Payment Form > **Bind the card on the customer ** js and css download address css:[Binding Card Payment CSS](https://foundphp.com/data/style/js/square/mysqpaymentform.css "Binding Card Payment js") Test environment: [Binding card payment js](https://foundphp.com/data/style/js/square/paymentform_dev.js "Binding card payment js") Formal environment: [Binding card payment js](https://foundphp.com/data/style/js/square/paymentform.js "Binding card payment js") ```js //Introduce js and css, formally develop and introduce paymentform.js
//html code of payment form
Bind Card
//js ``` ##### Bind Credit Card Submission Address ```php //credit card information $data_ary = array( 'cusid' => $P['customer_id'],//customer id 'nonce' => $P['nonce'], ); //binding card $result = $FoundPHP_pay->create_card($data_ary); print_R($result); ``` ##### Output Result ```php array( 'code' => 1, 'Use' => Create card, 'data' => array( 'card_id' => 'credit card id',//format:ccof:8WSBoMTj1Muoi****** 'card_brand'=> 'credit card type', 'last_four' => 'The last four digits of the credit card', 'exp_month' => 'effective month', 'exp_year' => 'effective year', ) ); ``` > ** Pay Directly with the Card ** js download address Test environment: [direct card payment js](https://foundphp.com/data/style/js/square/square_dev.js "direct payment js") Formal environment: [Direct card payment js](https://foundphp.com/data/style/js/square/square.js "Direct payment js") ```html //Judge the formal environment or the test environment //Load basic code of payment card
Pay 0.01
``` #### 4. Delete Credit Card ```php //submit credit card information $data_ary = array( 'customer' => '*****',//customer id 'card_id' => 'credit card id', ); //unified order $result = $FoundPHP_pay->del_card($data_ary); print_R($result); ``` ##### Output Result ```php array( 'code' => 1,//1 success 0 failure ); ``` #### 5. Credit cCrd Payment ```php //Submit payment information $data_ary = array( 'customer_id' => 'TYJB05H9Y8T4Z04V976BN*****',//Customer ID can be directly used for card payment without transmission 'card_id' => 'credit cardid', 'oid' => 'order number', 'moneys' => 'amount(cent)' ); //unified order $result = $FoundPHP_pay->create_pay($data_ary); print_R($result); ``` ##### Output Result ```php array( 'code' => 1, 'Use' => Pay, 'data' => array( 'payment_id' => 'Payment id',//for refund 'status'=> 'Status', //COMPLETED completed FAILED failed 'receipt_number'=> 'Status',//Payment receipt number ) ); ``` #### 6.Credit Card Refund ```php //submit refund information $data_ary = array( 'payment_id' => '*****',//payment id 'oid' => 'order number', 'moneys' => 'amount(cent)' ); //unified order $result = $FoundPHP_pay->refund_pay($data_ary); print_R($result); ``` ##### Output Result ```php array( 'code' => 1, 'Use' => Refund, 'data' => array( 'refund_id' => 'refundid',//for refund 'status'=> 'Status', //PENDING ready to refund COMPLETED completed FAILED failed 'payment_id'=> '',//payment id ) ); ```