Skip to content

Commit

Permalink
fix, using snap instead and update README.md (add example)
Browse files Browse the repository at this point in the history
  • Loading branch information
agung96tm committed Nov 14, 2023
1 parent affa224 commit 89b528e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,61 @@ MIDTRANS_SERVER_KEY=SB-Mid-server-xxXiKXXLpXXiKi6xxx
MIDTRANS_CLIENT_KEY=SB-Mid-client-xpTOkxxxxSsWTxxx
```

### Example
```typescript
import Midtrans from '@ioc:Agung96tm/Midtrans'

Route.get('/', async () => {
const result = await Midtrans.createTransaction({
payment_type: 'bank_transfer',
bank_transfer: { bank: 'bca' },
transaction_details: {
order_id: 'test-adonis-1',
gross_amount: 100000
},
item_details: [
{
id: 'test-adonis-1',
name: 'ayam bakar sambal balado',
quantity: 2,
price: 25000
},
{
id: 'test-adonis-item-1',
name: 'sop iga bakar daging lunak',
quantity: 1,
price: 30000
},
{
id: 'test-adonis-item-2',
name: 'just alpuckat',
quantity: 2,
price: 10000
}
],
customer_details: {
first_name: 'restu wahyu',
last_name: ' saputra',
email: 'restuwahyu13@zetmail.com',
phone: '087820154350',
billing_address: {
address: 'jl.sibuta gua hantu no.120',
city: 'Depok',
postal_code: '16436'
}
}
})

return result
/**
{
token: '1aa4d520-d6b2-4085-859c-5387f5bfdf11',
redirect_url: 'https://app.sandbox.midtrans.com/snap/v3/redirection/1aa4d520-d6b2-4085-859c-5387f5bfdf11'
}
**/
})
```

### Official

- [Midtrans Docs](https://docs.midtrans.com)
Expand Down
2 changes: 1 addition & 1 deletion providers/MidtransProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class MidtransProvider {
.use("Adonis/Core/Config")
.get("midtrans");

return new MidtransClient.CoreApi({
return new MidtransClient.Snap({
isProduction: isProduction,
serverKey: serverKey,
clientKey: clientKey,
Expand Down
6 changes: 3 additions & 3 deletions templates/contracts/midtrans.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module '@ioc:Agung96tm/Midtrans' {
import { MidtransClient } from 'midtrans-node-client'
import { MidtransSnap } from 'midtrans-node-client'

const midtrans: MidtransClient
export default midtrans
const midtrans: MidtransSnap
export default midtrans
}

0 comments on commit 89b528e

Please sign in to comment.