/**
  * Get items
  *
  * @see Pronamic_Pay_PaymentDataInterface::get_items()
  * @return Pronamic_IDeal_Items
  */
 public function get_items()
 {
     // Items
     $items = new Pronamic_IDeal_Items();
     // Amount
     $amount = filter_input(INPUT_POST, 'pronamic_pay_amount', FILTER_SANITIZE_STRING, array('flags' => FILTER_FLAG_ALLOW_THOUSAND, 'options' => array('decimal' => pronamic_pay_get_decimal_separator())));
     // Get correct amount if pronamic_pay_amount is an array
     if (!$amount && ($amount = filter_input(INPUT_POST, 'pronamic_pay_amount', FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY))) {
         // Array filter will remove values NULL, FALSE and empty strings ('')
         $amount = array_filter($amount);
         // Make sure the amount has the correct floating value
         foreach ($amount as $key => $value) {
             if ('other' !== $key) {
                 $amount[$key] = $value / 100;
             }
         }
         // Get first element of the array
         $amount = array_shift($amount);
     }
     $amount = Pronamic_WP_Pay_Util::string_to_amount($amount);
     // Item
     $item = new Pronamic_IDeal_Item();
     $item->setNumber($this->get_order_id());
     $item->setDescription(sprintf(__('Payment %s', 'pronamic_ideal'), $this->get_order_id()));
     $item->setPrice($amount);
     $item->setQuantity(1);
     $items->addItem($item);
     return $items;
 }
Ejemplo n.º 2
0
 /**
  * When the post is saved, saves our custom data.
  *
  * @param int $post_id The ID of the post being saved.
  */
 public function save_post($post_id)
 {
     // Check if our nonce is set.
     if (!filter_has_var(INPUT_POST, 'pronamic_pay_nonce')) {
         return $post_id;
     }
     $nonce = filter_input(INPUT_POST, 'pronamic_pay_nonce', FILTER_SANITIZE_STRING);
     // Verify that the nonce is valid.
     if (!wp_verify_nonce($nonce, 'pronamic_pay_save_form_options')) {
         return $post_id;
     }
     // If this is an autosave, our form has not been submitted, so we don't want to do anything.
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_id;
     }
     /* OK, its safe for us to save the data now. */
     $definition = array('_pronamic_payment_form_config_id' => FILTER_SANITIZE_NUMBER_INT, '_pronamic_payment_form_button_text' => FILTER_SANITIZE_STRING, '_pronamic_payment_form_amount_method' => FILTER_SANITIZE_STRING, '_pronamic_payment_form_amount_choices' => array('flags' => FILTER_REQUIRE_ARRAY));
     $data = filter_input_array(INPUT_POST, $definition);
     // Convert amount choices to cents
     if (isset($data['_pronamic_payment_form_amount_choices'])) {
         foreach ($data['_pronamic_payment_form_amount_choices'] as $i => $amount) {
             $amount = Pronamic_WP_Pay_Util::string_to_amount($amount);
             $data['_pronamic_payment_form_amount_choices'][$i] = Pronamic_WP_Pay_Util::amount_to_cents($amount);
         }
         // Remove empty choices
         $data['_pronamic_payment_form_amount_choices'] = array_filter($data['_pronamic_payment_form_amount_choices']);
     }
     // Update post meta data
     pronamic_pay_update_post_meta_data($post_id, $data);
 }