rizdaprasetya / midtrans-mobile-merchant-server--php-sample-

Sample for Midtrans mobile backend implementation written in PHP |
https://mobile-docs.midtrans.com
17 stars 29 forks source link

working? #1

Closed lordmen99 closed 6 years ago

lordmen99 commented 7 years ago

script ini saya coba bolak balik ngk jalan

rizdaprasetya commented 7 years ago

@lordmen99 silahkan dijelaskan maksud dari ngk jalan. Ada error message? ada screenshot? Silahkan dibaca juga di bagian Readme.md cara testingnya adalah menggunakan CURL request. https://github.com/rizdaprasetya/midtrans-mobile-merchant-server--php-sample-#testing

Jika dibuka di browser biasa, tidak akan bekerja sesuai fungsi. Thanks.

lordmen99 commented 7 years ago

udh ak fixing mas bro scriptmu, untuk script ini ngk working. perlu diubah lagi. coba aja post via postmen

rizdaprasetya commented 7 years ago

@lordmen99 Ya tentu, ada yang perlu diubah sesuai readme :

How to use Edit file charge/index.php, insert your Midtrans Account Server Key to <server key>. Upload these to your host, and make sure the url [your server endpoint]/charge can be accessed from the mobile app.

Scriptnya works, sudah tested dan dipakai beberapa orang lain. Bisa dicoba juga ditest di url https://supplement.ige.es/mobile/charge/, bisa via Postman/Curl/dll.

Kalau memang "script ini ngk working" dan "udh ak fixing mas bro scriptmu" silahkan ditunjukkan error & fix apa yang dipakai. Kalau bisa malah sekalian buat Pull Request agar bisa membantu orang lain dengan fix-nya.

Kalau tidak, saya anggap berarti tidak ada issue & akan saya close Issue ini karena kurang informatif. Thanks

billysusanto commented 6 years ago

Haloo mas @rizdaprasetya,

kodenya memang salah:

ini yang asli di web (hasil urlencode di postman): { "transaction_details": { "order_id": "mobile-12345", "gross_amount": 280000 }, "item_details": [ { "id": "A01", "price": 280000, "quantity": 1, "name": "Mie Ayam Komplit" } ], "customer_details": "email": "tester@example.com", "first_name": "Budi", "last_name": "Khannedy", "phone": "628112341234" } }

harusnya begini: { "transaction_details": { "order_id": "mobile-12345", "gross_amount": 280000 }, "item_details": [ { "id": "A01", "price": 280000, "quantity": 1, "name": "Mie Ayam Komplit" } ], "customer_details": [ { "email": "tester@example.com", "first_name": "Budi", "last_name": "Khannedy", "phone": "628112341234" }] }

sehingga muncul response: {"error_messages":["There was a problem in the JSON you submitted"]} *) saya pakai url Anda: https://supplement.ige.es/mobile/charge/

Saya buang waktu banyak sekali untuk solving, trnyata salah di dokumentasi. mohon segera diperbaiki agar tidak bikin orang bingung. thanks

iwsay commented 6 years ago

@billysusanto saya sudah coba dengan json yang baru masih tetap error mas. Tetap muncul response: {"error_messages":["There was a problem in the JSON you submitted"]} Yang saya coba seperti codenya seperti berikut ->

curl -X POST -d '{  
   "transaction_details":{  
      "order_id":"mobile-12345",
      "gross_amount":280000
   },
   "item_details":[  
      {  
         "id":"A01",
         "price":280000,
         "quantity":1,
         "name":"Mie Ayam Komplit"
      }
   ],
   "customer_details":[  
      {  
         "email":"tester@example.com",
         "first_name":"Budi",
         "last_name":"Khannedy",
         "phone":"628112341234"
      }
   ]
}' "https://supplement.ige.es/mobile/charge/"

ada solusi lain atau saya ada salah step? Terimakasih

rizdaprasetya commented 6 years ago

Hi all, Sebenernya saya juga bingung kenapa di tempat saya bisa dan jalan baik baik saja, tapi kalian pada report gak bisa. Saya beberapa kali udah coba lagi sesuai CURL command yg pernah saya tulis di readme:

curl -X POST -d '{
  "transaction_details": {
    "order_id": "mobile-12345",
    "gross_amount": 280000
  },
  "item_details": [
    {
      "id": "A01",
      "price": 280000,
      "quantity": 1,
      "name": "Mie Ayam Komplit"
    }
  ],
  "customer_details": {
    "email": "tester@example.com",
    "first_name": "Budi",
    "last_name": "Khannedy",
    "phone": "628112341234"
  }
}'  "https://supplement.ige.es/mobile/charge/"

Selalu berhasil dapet response: screen shot 2018-01-03 at 11 19 39 am

Info tambahan, PHP script yg saya host di https://supplement.ige.es/mobile/charge/ itu spesifikasi hostnya seperti ini: Platform: Google Compute Engine OS Version: Debian GNU/Linux 9.1 PHP version: 7.0.19

instance-1:~$ lsb_release -a
Distributor ID: Debian
Description:    Debian GNU/Linux 9.1 (stretch)
Release:    9.1
Codename:   stretch
instance-1:~$ php -v
PHP 7.0.19-1 (cli) (built: May 11 2017 14:04:47) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.19-1, Copyright (c) 1999-2017, by Zend Technologies

Hmm mungkin kalo ada yg gak berhasil, bisa jadi karena beda PHP version, atau CURL extension version. Karena saya pake PHP 7.

rizdaprasetya commented 6 years ago

Kalo dari comment mas @billysusanto

{
"transaction_details": {
"order_id": "mobile-12345",
"gross_amount": 280000
},
"item_details": [
{
"id": "A01",
"price": 280000,
"quantity": 1,
"name": "Mie Ayam Komplit"
}
],
-"customer_details": {
+"customer_details": [ {
"email": "tester@example.com",
"first_name": "Budi",
"last_name": "Khannedy",
"phone": "628112341234"
-}
+}]
}

Katanya parameter saya salah, dan harus ditambahin jadi array di bagian customer_details supaya berhasil. Justru kalau dijadiin array malah gak sesuai dengan dokumentasi API Snap: https://snap-docs.midtrans.com/#customer-details-object Karena memang customer_details itu harusnya object.

Terus saya coba beberapa kali juga gak pernah dapet error: {"error_messages":["There was a problem in the JSON you submitted"]} Saya gak ngerti sih gimana biar bisa dapet error itu, biar bisa bantu solvenya.

Untuk contoh parameter yang valid, mungkin bisa refer ke Postman Collections API Midtrans: https://github.com/rizdaprasetya/Midtrans-Payment-API-Postman-Collections

iwsay commented 6 years ago

kalo coba dari terminal sukses mas @rizdaprasetya , saya kemarin coba pakai postman dan muncul error itu. nah saya dapat error 406 Not Acceptable padahal saya sudah clone repo dan ganti server key. bisa bantu beri advice bagian mana yang harus saya cek?

rizdaprasetya commented 6 years ago

@iwsay Response code API 406 adalah karena Duplicate order ID. Order ID has already been utilized previously https://snap-docs.midtrans.com/#code-4xx

Silahkan ganti order id di JSON bodynya, 1 order id hanya bisa dipakai 1x

rizdaprasetya commented 6 years ago

Ok, ternyata yg bikin error adalah ketika command CURL-nya diimport ke postman, Postman auto parse sebagai application/x-www-form-urlencoded, yg tidak dikenali oleh API.

Kalau mau import ke postman harus ditambah content-type: application/json

curl -X POST \
  https://api.sandbox.veritrans.co.id/v2/charge \
  -H 'accept: application/json' \
  -H 'content-type: application/json' \
  -d '{
  "transaction_details": {
    "order_id": "mobile-12345",
    "gross_amount": 280000
  },
  "item_details": [
    {
      "id": "A01",
      "price": 280000,
      "quantity": 1,
      "name": "Mie Ayam Komplit"
    }
  ],
  "customer_details": {
    "email": "tester@example.com",
    "first_name": "Budi",
    "last_name": "Khannedy",
    "phone": "628112341234"
  }
}'

Will be added to readme, to avoid more confusion.