├── README.md └── PaymentPaypal.module /README.md: -------------------------------------------------------------------------------- 1 | PaymentPaypal 2 | ============= 3 | 4 | Paypal payment method for ProcessWire Shop module 5 | -------------------------------------------------------------------------------- /PaymentPaypal.module: -------------------------------------------------------------------------------- 1 | 'Paypal Payment Method', 11 | 'version' => 001, 12 | 'summary' => 'Paypal payment method for ProcessWire Shop', 13 | 'singular' => false, 14 | 'autoload' => false 15 | ); 16 | } 17 | public function init() { 18 | $this->title = __("Paypal (also credit card)"); 19 | } 20 | 21 | /* 22 | * 23 | * returns nothing. You should edit and save $order page. If payment was succesful, 24 | * then do $order->removeStatus(Page::statusUnpublished) and remember to save the order! 25 | * 26 | * If order was also paid, then do $order->sc_paid = time(); 27 | * 28 | * If order was not paid, but it was succesful (like invoice, money on delivery etc) 29 | * then just publish the order, but do not set sc_paid value. 30 | * 31 | * After you have manipulated the order, then just to redirect to $this->completedUrl 32 | * 33 | * 34 | * @param Page $order keeps the page object for the order 35 | * 36 | */ 37 | public function processPayment(Page $order) { 38 | 39 | $out = ''; 40 | 41 | if ($this->input->urlSegment(2) == "return") { 42 | $verify_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_notify-validate&' . http_build_query( $_POST ); 43 | 44 | if( !strstr( file_get_contents( $verify_url ), 'VERIFIED' ) ) { 45 | $out .= 'error when validating your payment.'; 46 | } else { 47 | $order->setOutputFormatting(false); 48 | $order->sc_paid = time(); 49 | $order->sc_paymentid = $this->sanitizer->text($_POST['txn_id']); 50 | $order->removeStatus(Page::statusUnpublished); 51 | $order->save(); 52 | $this->session->redirect($this->completedUrl); 53 | } 54 | } 55 | 56 | else if ($this->input->urlSegment(2) == "cancel") { 57 | $this->session->redirect($this->completedUrl); 58 | } else { 59 | // Let's generate the form code for Paypal data 60 | $http = ($this->config->https) ? 'https://' : 'http://'; 61 | $returnUrl = $http . $this->config->httpHost . $this->currentUrl . "return/"; 62 | $cancelUrl = $http . $this->config->httpHost . $this->currentUrl . "cancel/"; 63 | 64 | $out .= '
'; 103 | 104 | $out .= ""; 105 | } 106 | 107 | return $out; 108 | } 109 | 110 | static public function getModuleConfigInputfields(Array $data) { 111 | // this is a container for fields, basically like a fieldset 112 | $fields = new InputfieldWrapper(); 113 | 114 | // since this is a static function, we can't use $this->modules, so get them from the global wire() function 115 | $modules = wire('modules'); 116 | 117 | 118 | if(empty($data['currency'])) $data['currency'] = 'EUR'; 119 | if(empty($data['merchantSecret'])) $data['merchantSecret'] = '6pKF4jkv97zmqBJ3ZL8gUw5DfT2NMQ'; 120 | 121 | $field = $modules->get("InputfieldText"); 122 | $field->attr('name', 'business'); 123 | $field->attr('value', $data['business']); 124 | $field->label = "Paypal email"; 125 | $fields->add($field); 126 | 127 | $field = $modules->get("InputfieldText"); 128 | $field->attr('name', 'currency'); 129 | $field->attr('value', $data['currency']); 130 | $field->label = "Currency used (Paypal currency code)"; 131 | $fields->add($field); 132 | 133 | $field = $modules->get("InputfieldText"); 134 | $field->attr('name', 'location'); 135 | $field->attr('value', $data['location']); 136 | $field->label = "Location"; 137 | $field->description = "Location code, ie. GB"; 138 | $fields->add($field); 139 | 140 | $field = $modules->get("InputfieldText"); 141 | $field->attr('name', 'returntxt'); 142 | $field->attr('value', $data['returntxt']); 143 | $field->label = "Text on 'back to mysite.com' button at Paypal.com"; 144 | $fields->add($field); 145 | 146 | 147 | return $fields; 148 | } 149 | } 150 | --------------------------------------------------------------------------------