├── README.md ├── LICENSE ├── paymill.crt ├── index.html ├── subscription.php └── payment.php /README.md: -------------------------------------------------------------------------------- 1 | #Integration examples for PAYMILL PayButton 2 | 3 | There are 2 buttons in the index file of this Example. 4 | The first button uses the payment.php file to create transactions. 5 | The second button uses the subscription.php file to create subscriptions. 6 | 7 | ##Futher Information 8 | - https://developers.paymill.com/en/add-ons/paybutton/ 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Paymill 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /paymill.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIENjCCAx6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBvMQswCQYDVQQGEwJTRTEU 3 | MBIGA1UEChMLQWRkVHJ1c3QgQUIxJjAkBgNVBAsTHUFkZFRydXN0IEV4dGVybmFs 4 | IFRUUCBOZXR3b3Jr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20 | YINRsPkyPef89iYTx4AWpb9a/IfPeHmJIZriTAcKhjW88t5RxNKWt9x+Tu5w/Rw5 21 | 6wwCURQtjr0W4MHfRnXnJK3s9EK0hZNwEGe6nQY1ShjTK3rMUUKhemPR5ruhxSvC 22 | Nr4TDea9Y355e6cJDUCrat2PisP29owaQgVR1EX1n6diIWgVIEM8med8vSTYqZEX 23 | c4g/VhsxOBi0cQ+azcgOno4uG+GMmIPLHzHxREzGBHNJdmAPx/i9F4BrLunMTA5a 24 | mnkPIAou1Z5jJh5VkpTYghdae9C8x49OhgQ= 25 | -----END CERTIFICATE----- 26 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |"; 58 | var_dump($subscription); 59 | echo ""; 60 | } 61 | 62 | /** 63 | * Perform HTTP request to REST endpoint 64 | * 65 | * @param string $action 66 | * @param array $params 67 | * @param string $privateApiKey 68 | * 69 | * @return array 70 | */ 71 | function requestApi($action = '', $params = array(), $privateApiKey) 72 | { 73 | $curlOpts = array( 74 | CURLOPT_URL => "https://api.paymill.com/v2.1/" . $action, 75 | CURLOPT_RETURNTRANSFER => true, 76 | CURLOPT_CUSTOMREQUEST => 'POST', 77 | CURLOPT_USERAGENT => 'Paymill-php/0.0.2', 78 | CURLOPT_SSL_VERIFYPEER => true, 79 | CURLOPT_CAINFO => realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'paymill.crt', 80 | ); 81 | 82 | $curlOpts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&'); 83 | $curlOpts[CURLOPT_USERPWD] = $privateApiKey . ':'; 84 | 85 | $curl = curl_init(); 86 | curl_setopt_array($curl, $curlOpts); 87 | $responseBody = curl_exec($curl); 88 | $responseInfo = curl_getinfo($curl); 89 | if ($responseBody === false) { 90 | $responseBody = array('error' => curl_error($curl)); 91 | } 92 | curl_close($curl); 93 | 94 | if ('application/json' === $responseInfo['content_type']) { 95 | $responseBody = json_decode($responseBody, true); 96 | } 97 | 98 | return array( 99 | 'header' => array( 100 | 'status' => $responseInfo['http_code'], 101 | 'reason' => null, 102 | ), 103 | 'body' => $responseBody 104 | ); 105 | } 106 | 107 | /** 108 | * Perform API and handle exceptions 109 | * 110 | * @param $action 111 | * @param array $params 112 | * @param string $privateApiKey 113 | * 114 | * @return mixed 115 | */ 116 | function request($action, $params = array(), $privateApiKey) 117 | { 118 | if (!is_array($params)) { 119 | $params = array(); 120 | } 121 | 122 | $responseArray = requestApi($action, $params, $privateApiKey); 123 | $httpStatusCode = $responseArray['header']['status']; 124 | if ($httpStatusCode != 200) { 125 | $errorMessage = 'Client returned HTTP status code ' . $httpStatusCode; 126 | if (isset($responseArray['body']['error'])) { 127 | $errorMessage = $responseArray['body']['error']; 128 | } 129 | 130 | return array("data" => array( 131 | "error" => $errorMessage, 132 | "http_status_code" => $httpStatusCode 133 | )); 134 | } 135 | 136 | return $responseArray['body']['data']; 137 | } 138 | -------------------------------------------------------------------------------- /payment.php: -------------------------------------------------------------------------------- 1 | $token, 21 | 'client' => $client['id'] 22 | ), 23 | $privateApiKey 24 | ); 25 | 26 | $transaction = request( 27 | 'transactions/', 28 | array( 29 | 'amount' => $amount, 30 | 'currency' => $currency, 31 | 'client' => $client['id'], 32 | 'payment' => $payment['id'], 33 | 'description' => $description 34 | ), 35 | $privateApiKey 36 | ); 37 | 38 | $isStatusClosed = isset($transaction['status']) && $transaction['status'] == 'closed'; 39 | 40 | $isResponseCodeSuccess = isset($transaction['response_code']) && $transaction['response_code'] == 20000; 41 | 42 | if ($isStatusClosed && $isResponseCodeSuccess) { 43 | echo 'Transaction successful!'; 44 | } else { 45 | echo 'Transaction not successful!
"; 49 | var_dump($transaction); 50 | echo ""; 51 | } 52 | 53 | /** 54 | * Perform HTTP request to REST endpoint 55 | * 56 | * @param string $action 57 | * @param array $params 58 | * @param string $privateApiKey 59 | * 60 | * @return array 61 | */ 62 | function requestApi($action = '', $params = array(), $privateApiKey) 63 | { 64 | $curlOpts = array( 65 | CURLOPT_URL => "https://api.paymill.com/v2.1/" . $action, 66 | CURLOPT_RETURNTRANSFER => true, 67 | CURLOPT_CUSTOMREQUEST => 'POST', 68 | CURLOPT_USERAGENT => 'Paymill-php/0.0.2', 69 | CURLOPT_SSL_VERIFYPEER => true, 70 | CURLOPT_CAINFO => realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'paymill.crt', 71 | ); 72 | 73 | $curlOpts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&'); 74 | $curlOpts[CURLOPT_USERPWD] = $privateApiKey . ':'; 75 | 76 | $curl = curl_init(); 77 | curl_setopt_array($curl, $curlOpts); 78 | $responseBody = curl_exec($curl); 79 | $responseInfo = curl_getinfo($curl); 80 | if ($responseBody === false) { 81 | $responseBody = array('error' => curl_error($curl)); 82 | } 83 | curl_close($curl); 84 | 85 | if ('application/json' === $responseInfo['content_type']) { 86 | $responseBody = json_decode($responseBody, true); 87 | } 88 | 89 | return array( 90 | 'header' => array( 91 | 'status' => $responseInfo['http_code'], 92 | 'reason' => null, 93 | ), 94 | 'body' => $responseBody 95 | ); 96 | } 97 | 98 | /** 99 | * Perform API and handle exceptions 100 | * 101 | * @param $action 102 | * @param array $params 103 | * @param string $privateApiKey 104 | * 105 | * @return mixed 106 | */ 107 | function request($action, $params = array(), $privateApiKey) 108 | { 109 | if (!is_array($params)) { 110 | $params = array(); 111 | } 112 | 113 | $responseArray = requestApi($action, $params, $privateApiKey); 114 | $httpStatusCode = $responseArray['header']['status']; 115 | if ($httpStatusCode != 200) { 116 | $errorMessage = 'Client returned HTTP status code ' . $httpStatusCode; 117 | if (isset($responseArray['body']['error'])) { 118 | $errorMessage = $responseArray['body']['error']; 119 | } 120 | $responseCode = ''; 121 | if (isset($responseArray['body']['data']['response_code'])) { 122 | $responseCode = $responseArray['body']['data']['response_code']; 123 | } 124 | 125 | return array("data" => array( 126 | "error" => $errorMessage, 127 | "response_code" => $responseCode, 128 | "http_status_code" => $httpStatusCode 129 | )); 130 | } 131 | 132 | return $responseArray['body']['data']; 133 | } 134 | --------------------------------------------------------------------------------