Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. <?php
  2. /*
  3. * Example 1 - How to prepare a new payment with the Mollie API.
  4. */
  5.  
  6. $amount = 100.50;
  7. $description = "Booking for Villa Hijau";
  8. $days = 10;
  9. $name = "####";
  10. $email = "####";
  11.  
  12. try {
  13. /*
  14. * Initialize the Mollie API library with your API key.
  15. *
  16. * See: https://www.mollie.com/beheer/account/profielen/
  17. */
  18. include "initialize.php";
  19.  
  20. /*
  21. * Generate a unique order id for this example. It is important to include this unique attribute
  22. * in the redirectUrl (below) so a proper return page can be shown to the customer.
  23. */
  24. $order_id = time();
  25.  
  26. /*
  27. * Determine the url parts to these example files.
  28. */
  29. $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http";
  30. $hostname = $_SERVER['HTTP_HOST'];
  31. $path = dirname(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']);
  32.  
  33. /*
  34. * Payment parameters:
  35. * amount Amount in EUROs. This example creates a € 10,- payment.
  36. * description Description of the payment.
  37. * redirectUrl Redirect location. The customer will be redirected there after the payment.
  38. * webhookUrl Webhook location, used to report when the payment changes state.
  39. * metadata Custom metadata that is stored with the payment.
  40. */
  41. $payment = $mollie->payments->create(array(
  42. "amount" => $amount,
  43. "description" => $description,
  44. "redirectUrl" => "{$protocol}://{$hostname}{$path}/03-return-page.php?order_id={$order_id}",
  45. "webhookUrl" => "{$protocol}://{$hostname}{$path}/02-webhook-verification.php",
  46. "metadata" => array(
  47. "order_id" => $order_id
  48. )
  49. ));
  50.  
  51. /*
  52. * In this example we store the order with its payment status in a database.
  53. */
  54. database_write($order_id, $payment->status, $amount, $description, $days, $name, $email);
  55.  
  56. /*
  57. * Send the customer off to complete the payment.
  58. */
  59. header("Location: " . $payment->getPaymentUrl());
  60. }
  61. catch (Mollie_API_Exception $e) {
  62. echo "API call failed: " . htmlspecialchars($e->getMessage());
  63. }
  64.  
  65.  
  66. /*
  67. * NOTE: This example uses a text file as a database. Please use a real database like MySQL in production code.
  68. */
  69. function database_write($order_id, $status, $amount, $description, $days, $name, $email)
  70. {
  71. $db_user = 'mollie';
  72. $db_pass = '####';
  73. $order_id = intval($order_id);
  74. // Use $status to get the order status
  75. $dbh = new PDO('mysql:host=localhost;dbname=orders', $db_user, $db_pass);
  76. $stmt = "INSER INTO order (id, order_name, order_description, order_amount, order_customer, order_customer_email, order_status) VALUES (?,?,?,?,?,?,?)";
  77. if($stmt){
  78. $stmt->bindParam($order_id,$name,$description,$amount,$name,$email,$status);
  79. $stmt->execute();
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement