예제 #1
0
 /**
  * Start
  *
  * @param Pronamic_Pay_PaymentDataInterface $data
  * @see Pronamic_WP_Pay_Gateway::start()
  */
 public function start(Pronamic_Pay_PaymentDataInterface $data, Pronamic_Pay_Payment $payment, $payment_method = null)
 {
     $request = new Pronamic_WP_Pay_Gateways_Mollie_PaymentRequest();
     $request->amount = $data->get_amount();
     $request->description = $data->get_description();
     $request->redirect_url = add_query_arg('payment', $payment->get_id(), home_url('/'));
     $request->locale = Pronamic_WP_Pay_Mollie_LocaleHelper::transform($data->get_language());
     switch ($payment_method) {
         case Pronamic_WP_Pay_PaymentMethods::CREDIT_CARD:
             $request->method = Pronamic_WP_Pay_Mollie_Methods::CREDITCARD;
             break;
         case Pronamic_WP_Pay_PaymentMethods::MISTER_CASH:
             $request->method = Pronamic_WP_Pay_Mollie_Methods::MISTERCASH;
             break;
         case Pronamic_WP_Pay_PaymentMethods::SOFORT:
             $request->method = Pronamic_WP_Pay_Mollie_Methods::SOFORT;
             break;
         case Pronamic_WP_Pay_PaymentMethods::IDEAL:
             // @since 1.1.2
             $request->method = Pronamic_WP_Pay_Mollie_Methods::IDEAL;
             break;
     }
     $result = $this->client->create_payment($request);
     if ($result) {
         $payment->set_transaction_id($result->id);
         $payment->set_action_url($result->links->paymentUrl);
     } else {
         $this->error = $this->client->get_error();
     }
 }
예제 #2
0
 /**
  * Start
  *
  * @see Pronamic_WP_Pay_Gateway::start()
  */
 public function start(Pronamic_Pay_Payment $payment)
 {
     $request = new Pronamic_WP_Pay_Gateways_Mollie_PaymentRequest();
     $payment_method = $payment->get_method();
     $request->amount = $payment->get_amount();
     $request->description = $payment->get_description();
     $request->redirect_url = $payment->get_return_url();
     $request->webhook_url = $this->get_webhook_url();
     $request->locale = Pronamic_WP_Pay_Mollie_LocaleHelper::transform($payment->get_language());
     $request->method = Pronamic_WP_Pay_Mollie_Methods::transform($payment_method);
     if (empty($request->method) && !empty($payment_method)) {
         // Leap of faith if the WordPress payment method could not transform to a Mollie method?
         $request->method = $payment_method;
     }
     // Customer ID
     $user_id = $payment->post->post_author;
     $customer_id = $this->get_customer_id_by_wp_user_id($user_id);
     if (empty($customer_id)) {
         $customer_id = $this->client->create_customer($payment->get_email(), $payment->get_customer_name());
         if ($customer_id) {
             $this->update_wp_user_customer_id($user_id, $customer_id);
         }
     }
     $payment->set_meta('mollie_customer_id', $customer_id);
     // Subscriptions
     $subscription = $payment->get_subscription();
     $subscription_methods = array(Pronamic_WP_Pay_PaymentMethods::CREDIT_CARD, Pronamic_WP_Pay_PaymentMethods::DIRECT_DEBIT_IDEAL);
     if ($subscription && in_array($payment_method, $subscription_methods, true)) {
         if (is_object($this->client->get_error())) {
             // Set error if customer could not be created
             $this->error = $this->client->get_error();
             // Prevent subscription payment from being created without customer
             return;
         }
         $request->recurring_type = Pronamic_WP_Pay_Mollie_Recurring::RECURRING;
         $request->method = Pronamic_WP_Pay_Mollie_Methods::transform($payment_method);
         if (Pronamic_WP_Pay_PaymentMethods::DIRECT_DEBIT_IDEAL === $payment_method) {
             // Use direct debit for recurring payments with payment method `Direct Debit (mandate via iDEAL)`.
             $request->method = Pronamic_WP_Pay_Mollie_Methods::DIRECT_DEBIT;
         }
         if ($subscription->has_valid_payment() && !$customer_id) {
             // Get customer ID from first payment
             $first = $subscription->get_first_payment();
             $customer_id = $first->get_meta('mollie_customer_id');
             $payment->set_meta('mollie_customer_id', $customer_id);
         }
         $can_user_interact = in_array($payment->get_source(), array('gravityformsideal'), true);
         // Mandate payment method to check for.
         $mandate_method = $payment_method;
         if (Pronamic_WP_Pay_PaymentMethods::DIRECT_DEBIT_IDEAL === $mandate_method) {
             $mandate_method = Pronamic_WP_Pay_PaymentMethods::DIRECT_DEBIT;
         }
         if (!$this->client->has_valid_mandate($customer_id, $mandate_method) && (!$subscription->has_valid_payment() || $can_user_interact)) {
             // First payment or if user interaction is possible and no valid mandates are found
             $request->recurring_type = Pronamic_WP_Pay_Mollie_Recurring::FIRST;
             if (Pronamic_WP_Pay_PaymentMethods::DIRECT_DEBIT_IDEAL === $payment_method) {
                 // Use iDEAL for first payments with payment method `Direct Debit (mandate via iDEAL)`.
                 $request->method = Pronamic_WP_Pay_Mollie_Methods::IDEAL;
             }
         }
         if (Pronamic_WP_Pay_Mollie_Recurring::RECURRING === $request->recurring_type) {
             // Recurring payment
             $payment->set_action_url($payment->get_return_url());
             if ($subscription->has_valid_payment()) {
                 // Use subscription amount if this is not the initial payment.
                 $payment->amount = $subscription->get_amount();
             }
         }
     }
     if (Pronamic_WP_Pay_PaymentMethods::IDEAL === $payment_method) {
         // If payment method is iDEAL we set the user chosen issuer ID.
         $request->issuer = $payment->get_issuer();
     }
     $request->customer_id = $customer_id;
     $result = $this->client->create_payment($request);
     if (!$result) {
         $this->error = $this->client->get_error();
         return;
     }
     if ($subscription && Pronamic_WP_Pay_Mollie_Recurring::RECURRING === $request->recurring_type) {
         $subscription->set_status(Pronamic_WP_Pay_Mollie_Statuses::transform($result->status));
     }
     $payment->set_transaction_id($result->id);
     if ('' === $payment->get_action_url()) {
         $payment->set_action_url($result->links->paymentUrl);
     }
 }
예제 #3
0
 /**
  * @dataProvider locale_matrix_provider
  */
 public function test_get_locale($locale, $expected)
 {
     $mollie_locale = Pronamic_WP_Pay_Mollie_LocaleHelper::transform($locale);
     $this->assertEquals($expected, $mollie_locale);
 }